wml <br /> and \n

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
swartbees
Forum Newbie
Posts: 5
Joined: Wed Mar 31, 2004 9:59 am

wml <br /> and \n

Post by swartbees »

Hi there

I have a function which takes my wml string and converts all <br/> to \n:

function br2nl($string) {
$br = array('<br/>','<br />','<BR>','<BR/>','<BR />');
return str_replace($br,'\n',$string);
}

It seems to work fine when I do the following

$string = "This <br/> is my <br/> string";
echo br2nl($string);
//returns "This \n is my \n string"

When however I mail this string with phpmailer to a sms server the output that I get via sms is "This/n is my /n string".

I've tested:

$string = This \n is my \n string"

and it works fine. So somewhere in the string that my br2nl function returns thre must be special characters which mess up my mail. :evil:

Any suggestions on how to see what all the special characters are and how to remedy this?

Regards
swartbees
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

A stab in the dark, but what if you escape the \n like \\n?
swartbees
Forum Newbie
Posts: 5
Joined: Wed Mar 31, 2004 9:59 am

Post by swartbees »

Tried that, but it doesn't work either :cry:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Put the \n in double quotes maybe, so "\n" in the str_replace() not '\n'?

Mac
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

why are you replacing <br/> with \n <br/> works just fine in wml
swartbees
Forum Newbie
Posts: 5
Joined: Wed Mar 31, 2004 9:59 am

Post by swartbees »

BRILLIANT! It works!

Thanx
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

....whos works...mine or twigletmac???
Post Reply