Bolanb Posted February 27, 2009 Share Posted February 27, 2009 What I'm looking for is to check if every new line of a string contains a '=' and then make it bold, while a line break unbolds it. I've been testing a few things out and just can't figure it out. If anyone could help me here, you'll get my <3 and gratitude. Link to comment https://forums.phpfreaks.com/topic/147113-replacing-first-letter-of-every-new-line/ Share on other sites More sharing options...
asmith Posted February 27, 2009 Share Posted February 27, 2009 Try this : <?php $string = ' Some text content content<br /> =content content content content content content<br /> content content content content content content<br /> =content content content content content content<br /> content content content content content content '; //explode your string with new lines. $string_array = explode('<br />',$string); // replace <br /> with \n if you are using normal line break //now check the array to find out if they contain = at first. foreach ($string_array as $line_key => $the_line) { if (substr(trim($the_line),0,1) == '=') $string_array[$line_key] = '=<b>'.substr(trim($the_line),1).'</b>'; // replacing the line in array with the bold version. } echo implode('<br />',$string_array); // replace <br /> with \n if you are using normal line break ?> Link to comment https://forums.phpfreaks.com/topic/147113-replacing-first-letter-of-every-new-line/#findComment-772412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.