I'm trying to double line breaks in a user-entered field into XML. I've tried matching them with a simple regexp:
'<paragraph>' . preg_replace('/^^/m', "</paragraph>\n\n<paragraph>", $_POST['post']); . '</paragraph>'This does seem to be matching the paragraphs, but it goes over the top. For example,
All right, no-one seems to have a clue. Perhaps relevant: I'm using Windows which uses [lf][cr] to mark new lines, compared to unix where simply [lf] is used. Could this be why?
01-23-2004, 03:07 PM
thats exactly the reason
run an str replace to delete all occurances of \r
as for matching double line breaks why not use "'\n\n's" ? ( i use a single quote as a delimiter)
Finally got it to work! Thanks! Here's my final code:
$postnew = str_replace("\r", '', $_POST['post']);
$postnew = str_replace("\n\n", "[ot]/paragraph[ct]\n\n[ot]paragraph[ct]", $postnew);
01-23-2004, 06:51 PM
Just a comment,
Thanks for posting your solution. All to often I notice people get things to work and simply post something like "I got it, thanks". Although this is great, It really annoys me when I search this forum and can't find the answer because it wasn't added at the end of the thread.
I know I too am guilty, but I just wanted to point it out and say thanks me' :thumbsup:
01-23-2004, 10:52 PM
am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?
Originally posted by bcarl314
I know I too am guilty, but I just wanted to point it out and say thanks me' :thumbsup: No problem:thumbsup:
am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?Yep, I was passing a string with < and > into an XSLT file, and getting well formed errors, so I swapped out < and > with [ot] and [ct], and use another str_replace later on.