Extract <BR> from mySQL data

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

scoobysteve
New php-forum User
New php-forum User
Posts: 15
Joined: Thu May 31, 2012 1:08 am

Extract <BR> from mySQL data

Postby scoobysteve » Mon Aug 11, 2014 5:59 am

Hi all I have a php script that generates a xml file from data in my mySQL database. Its all working perfect but I need to extract the new lines that are stored in the database field. At the moment I am using this format

$xml .= "<Features>".$r["Bullet1"]."</Features>";

I am trying to nl2br but it will not work no matter what I try.

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

Any ideas please
Thanks in advance
Steve

landi
php-forum Active User
php-forum Active User
Posts: 301
Joined: Thu Mar 15, 2012 3:59 pm

Re: Extract <BR> from mySQL data

Postby landi » Mon Aug 11, 2014 7:56 am

Hi,
It would help us to see the data before and after!
This works for me:

Code: Select all

   <?php
      $a = "abc\n";
      print bin2hex($a) .'<br>';
      $b = nl2br($a);
      print bin2hex($b) .'<br>';
   ?>

Results:

Code: Select all

6162630a  // abc\n
6162633c6272202f3e0a // abc<br />\n


-A

scoobysteve
New php-forum User
New php-forum User
Posts: 15
Joined: Thu May 31, 2012 1:08 am

Re: Extract <BR> from mySQL data

Postby scoobysteve » Mon Aug 11, 2014 10:15 pm

Thanks for you post.

The only form that seems to work is this
$xml .= "<Features><![CDATA[".$r["Bullet1"]."]]></Features>";

which outputs this
<Features>
<![CDATA[
44SQM RENOVATED THROUGHOUT TO A HIGH STANDARD DOUBLE BEDROOM WITH FITTED WARDROBE MODERN FITTED KITCHEN ZANUSSI APPLIANCES BATHROOM WC
]]>
</Features>

when what I really need is the output to look like this, but what happens is it either fails to output at all and fails or it skips over the Features Child to the next inline.

<Features>
<![CDATA[
44SQM
RENOVATED THROUGHOUT TO A HIGH STANDARD
DOUBLE BEDROOM WITH FITTED WARDROBE
MODERN FITTED KITCHEN
ZANUSSI APPLIANCES
BATHROOM
WC
]]>
</Features>

landi
php-forum Active User
php-forum Active User
Posts: 301
Joined: Thu Mar 15, 2012 3:59 pm

Re: Extract <BR> from mySQL data

Postby landi » Tue Aug 12, 2014 12:20 am

Hi,
1) Please post the bin2hex() of that data as suggested above. I really can't respond further if you can't work with me on this.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests