Valleriani Posted May 14, 2007 Share Posted May 14, 2007 Right now I have this set of code for ( $counter = 1; $counter <= $count; $counter += 1) { $content['post_content'] = str_replace($pieces[$counter], '<strong>' . $pieces[$counter] . '</strong>', $content['post_content']); } What it does is change any keywords in the content to have a bold feel to it, pretty simple enough. The issue is, sometimes the keyword is in image links or links in general, for example: $content['post_content'] = There is a bull here, a big bull! <img src="www.bigbull.com"> Generally it should just bold the two first ones, but not the last one (One's in < >'s basically shouldn't be).. Right now it would come out like <img src="www.big<strong>bull</strong>.com"> Which is a nasty booboo... Can anyone help me out, or give me advise on how to zap this issue? Thanks! Link to comment https://forums.phpfreaks.com/topic/51245-php-replace-where-needed-only/ Share on other sites More sharing options...
marf Posted May 14, 2007 Share Posted May 14, 2007 This is how I think you could do it Keep that initial for loop. Then do a search to find the location of the keyword. If it finds the location Check the first character after and before the keyword, if before is a Space, after is a space, OR before is a period after is a space, OR before and after are spaces, then it isn't a part of a link like that. Then you can add the strong. Repeat that for all occurances of the keyword. Something like that should work. Link to comment https://forums.phpfreaks.com/topic/51245-php-replace-where-needed-only/#findComment-252454 Share on other sites More sharing options...
effigy Posted May 14, 2007 Share Posted May 14, 2007 See this post. Link to comment https://forums.phpfreaks.com/topic/51245-php-replace-where-needed-only/#findComment-252503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.