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! Quote Link to comment Share on other sites More sharing options...
DJTim666 Posted July 16, 2008 Share Posted July 16, 2008 http://www.php.net/str_replace Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Madatan Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks! Worked like a charm! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.