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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scoobysteve
Forum Newbie
Posts: 14
Joined: Wed Jul 30, 2014 5:19 am

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

Post 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
Last edited by scoobysteve on Mon Aug 11, 2014 7:10 am, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

ereg_replace has been deprecated. Sounds like you want a simple nl2br() though.
scoobysteve
Forum Newbie
Posts: 14
Joined: Wed Jul 30, 2014 5:19 am

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

Post 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>";
Post Reply