justravis Posted September 17, 2007 Share Posted September 17, 2007 thanks for reading my thread. isnt ^ common regex notation? keep getting this error: Parse error: syntax error, unexpected '^' $goalsheet.=preg_replace("/^[0-9]+ Year Career Goal #[0-9]+: *$\", "/^<span class=hd2>[0-9]+ Year Career Goal #[0-9]+: *</span><br>$/", $goallist); aside from the error, i think the regex is off, but i hav had a hard time understanding how I can ignore text in the middle. Here are some examples of what i'm trying to do: "1 Year Goal #1: Web Developer" -> "<span>1 Year Goal #1: Web Developer</span><br>" "10 Year Goal #2: IT Consultant" -> "<span>10 Year Goal #2: IT Consultant</span><br>" suggestions? Link to comment https://forums.phpfreaks.com/topic/69672-php-replace-the-start-end-of-string-using-regular-expressions-preg_replace/ Share on other sites More sharing options...
sasa Posted September 18, 2007 Share Posted September 18, 2007 try <?php $goallist = '1 Year Goal #1: Web Developer'; //$goallist = '10 Year Goal #2: IT Consultant'; echo $goalsheet = preg_replace("/^([0-9]+) Year Goal #([0-9]+: .*)$/", "<span class='hd2'>$1 Year Career Goal #$2</span><br>", $goallist); ?> or $goalsheet = "<span class='hd2'>" . $goallist . "</span><br>"; Link to comment https://forums.phpfreaks.com/topic/69672-php-replace-the-start-end-of-string-using-regular-expressions-preg_replace/#findComment-350545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.