Madatan Posted July 16, 2008 Share Posted July 16, 2008 Not sure the title is that good, i'm not really sure how to put this. But what I want to do is this. I have a news script on my site adding news, anyone can add at any time. What I would like to do is that when someone add the chars 1/10 for example I would like it to be replaced with an image when people read the news article. Is this possible and how to? Thanks for you help! Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/ Share on other sites More sharing options...
DJTim666 Posted July 16, 2008 Share Posted July 16, 2008 http://www.php.net/str_replace Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/#findComment-591695 Share on other sites More sharing options...
effigy Posted July 16, 2008 Share Posted July 16, 2008 What patterns are you after? Does 2/10 get replaced also? Are these dates? ...fractions? Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/#findComment-591696 Share on other sites More sharing options...
Madatan Posted July 16, 2008 Author Share Posted July 16, 2008 What patterns are you after? Does 2/10 get replaced also? Are these dates? ...fractions? Yes 1/10 to 10/10 will be replaced with different amounts of images, these are ratings. So 1/10 one image, 10/10 ten images. Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/#findComment-591700 Share on other sites More sharing options...
effigy Posted July 16, 2008 Share Posted July 16, 2008 Something like this: <pre> <?php $str = '0/10 1/10 2/10 3/10 4/10 5/10 6/10 7/10 8/10 9/10 10/10 11/10'; echo preg_replace('%\b([2-9]|10?)/10\b%', '<img src="rating_$1.gif">', $str); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/#findComment-591710 Share on other sites More sharing options...
Madatan Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks! Worked like a charm! Link to comment https://forums.phpfreaks.com/topic/115060-solved-how-to-change-a-certain-string-to-symbols-help/#findComment-591713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.