190 PALMER RD, HARMONY
MLS® 201512263 $239,900
2 ACRES/HEATED DBL GARAGE/HEAT PUMP
http://goo.gl/tVWDan
I want the above first line '190 PALMER RD, HARMONY' replaced with : <p style="color: #EF2F48"> <b> 190 PALMER RD, HARMONY </b> </p>
using regex in PHP.
I used the following code. But doesn't work. Please help.
(^[0-9].*) - <p style="color: #EF2F48"> <b> \1 </b> </p>
I want the above second line 'MLS® 201512263 $239,900' replaced with : <p> MLS® 201512263 $239,900 </p>
using regex.
I used the following code. But works.
(MLS®[0-9]*) (\$[0-9,]+) - <p> \1 \2 </p>
And I want the third line select by regex. I am not sure. I want like this. <p style="color: #000"> 2 ACRES/HEATED DBL GARAGE/HEAT PUMP </p>
Fourth line I selected like this way and replaced.
(http:*.*) - <p><a class="ui-link" style="color: blue;"href="\1" target="_blank">\1</a></p>
Please help me.
Manoj
Try following script:
$rx = '/^([^
]+)\s*([^
]+) (\$[^
]+)\s*([^
]+)\s*([^
]+)$/sim';
$replacement = '<p style="color: #EF2F48"><b>$1</b></p><p>$2  $3</p> <p style="color: #000">$3</p> <p><a class="ui-link" style="color: blue;"href="$4" target="_blank">$5</a></p>';
$subject = ".... your test data ....";
$result = preg_replace($rx, $replacement, $subject);
Result:
<p style="color: #EF2F48"><b>190 PALMER RD, HARMONY</b></p>
<p>MLS® 201512263  $239,900</p>
<p style="color: #000">$239,900</p>
<p>
<a class="ui-link" style="color: blue;"href="2 ACRES/HEATED DBL GARAGE/HEAT PUMP" target="_blank">
http://goo.gl/tVWDan</a>
</p>
See Demo here