Page 1 of 1

Need to include <BR> in php to xml script.

Posted: Mon Aug 11, 2014 7:05 am
by scoobysteve
Hi folks I have a php script running on a cron job that produces a xml file from the data in my MySQL database, its all working great but I would like to include the line breaks that appear in the data field Bullet1. The code below works fine but outputs all the text straight after each other.

$xml .= "<Features><![CDATA[".$r["Bullet1"]."]]></Features>";
or
$xml .= "<Location>".$r["NearestTown"]."</Location>";

I am trying to use this type of code to add a <BR> but its not working any help would be appreciated.

$xml .= "<Features><![CDATA[".stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />".$r["Bullet1"]))."]]></Features>";
or
$xml .= "<Location>".stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />".$r["Bullet1"]))."</Location>";


Steve

Re: Need to include <BR> in php to xml script.

Posted: Mon Aug 11, 2014 7:10 am
by Celauran
ereg_replace has been deprecated. Sounds like you want a simple nl2br() though.

Re: Need to include <BR> in php to xml script.

Posted: Mon Aug 11, 2014 7:21 am
by scoobysteve
Thanks again.

I can get that to work in a normal php listing all vaules using

echo nl2br($row['Bullet1']);

But I cant seem to get it to work in the xml export script.

$xml .= "<Location>".nl2br($r['Bullet1'])."</Location>";

this works below but does not includes <BR>
$xml .= "<Location>".$r["Bullet1"]."</Location>";