myares Posted March 8, 2010 Share Posted March 8, 2010 i want to replace a part of a variable ($) but i can't figure it out suppose, if $a = 'this is a title'; I want to replace it as $a = '<b>this is</b> a title'; or $a = '<b>this</b> is a title'; can someone help me? Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/ Share on other sites More sharing options...
thewooleymammoth Posted March 8, 2010 Share Posted March 8, 2010 $a = str_replace('this', '<b>this</b>', $a); http://us.php.net/manual/en/function.str-replace.php Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022875 Share on other sites More sharing options...
myares Posted March 8, 2010 Author Share Posted March 8, 2010 $a = str_replace('this', '<b>this</b>', $a); http://us.php.net/manual/en/function.str-replace.php well... i am not only talking about the text "this is a title" i want a code which will put something like (<b>) before the first word of the text and (</b>) after the first word of the text.. whatever the text is. Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022877 Share on other sites More sharing options...
thewooleymammoth Posted March 8, 2010 Share Posted March 8, 2010 http://www.regular-expressions.info/php.html Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022879 Share on other sites More sharing options...
myares Posted March 8, 2010 Author Share Posted March 8, 2010 http://www.regular-expressions.info/php.html thank but more accurate help would be better because i'm not much familiar in using regular expressions. Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022880 Share on other sites More sharing options...
Rustywolf Posted March 8, 2010 Share Posted March 8, 2010 <?php $list = explode(" ", $input); $first_word = str_replace($list[0], "<b>" . $list[0] . "</b>", $input); ?> Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022890 Share on other sites More sharing options...
myares Posted March 8, 2010 Author Share Posted March 8, 2010 <?php $list = explode(" ", $input); $first_word = str_replace($list[0], "<b>" . $list[0] . "</b>", $input); ?> Thanks a lot mate.. it worked. It freaked me out when no one was replying. Thanks! Link to comment https://forums.phpfreaks.com/topic/194470-php-coding-help/#findComment-1022918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.