makeshift_theory Posted January 18, 2007 Share Posted January 18, 2007 Okay, here is my problem. I am using AJAX to pull in the process.php file and when I was doing it before AJAX it retaining the "\r\n" so I could replace those into <br>. However since implementing AJAX it will not add breaks from the textarea despite my best attempts here is the code:AJAX CODE:[code] function requestContent(url) { var vartest = document.post.testfield.value; vartest.replace("%0D","<br>"); xmlhttp.open("GET",url + "?testfield=" + vartest,true); xmlhttp.onreadystatechange =statusListener; xmlhttp.send(null); }//statusListener function is called automatically whenever readystate value of XMLHttpRequest Object changes.//see xmlhttp.onreadystatechange =statusListener; statement above.//When readystate is 1, its a loading state.//When readystate is 4, content is loaded function statusListener() { if (xmlhttp.readyState == 1) { document.getElementById("content").innerHTML= "loading..."; } if (xmlhttp.readyState == 4) { //xmlhttp.responseText is the content of document requested document.getElementById("content").innerHTML=xmlhttp.responseText; } }[/code]Process:[code] $data = $_GET['testfield']; $code = array("&" => "&", "\r" => "<br>", "\n" => "<br>", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/a]" => "</a>", "[/img]" => "'>", ); $data = str_replace(array_keys($code), array_values($code), $data); $urlbegin = '/(\[a src=)(.*)(\])/'; $link = '<a href="${2}">${4}'; $data = preg_replace($urlbegin, $link, $data); echo $data;[/code] Link to comment https://forums.phpfreaks.com/topic/34729-breaks-not-showing-up/ Share on other sites More sharing options...
makeshift_theory Posted January 18, 2007 Author Share Posted January 18, 2007 well after playing around I managed to get the breaks to show, but only one break will show:[code]//call this function with url of document to open as attribute function requestContent(url) { var vartest = document.post.testfield.value; vartest = vartest.replace(/\n/,"<br>"); vartest = vartest.replace(/\r/,"<br>"); xmlhttp.open("GET",url + "?testfield=" + vartest,true); xmlhttp.onreadystatechange =statusListener; xmlhttp.send(null); }[/code]I changed the pattern, however is there a way to loop it? Link to comment https://forums.phpfreaks.com/topic/34729-breaks-not-showing-up/#findComment-163665 Share on other sites More sharing options...
mainewoods Posted January 18, 2007 Share Posted January 18, 2007 use the global modifier 'g' on the end of your regular expression:[code]vartest = vartest.replace(/\r\n/g,"<br>");[/code] Link to comment https://forums.phpfreaks.com/topic/34729-breaks-not-showing-up/#findComment-163809 Share on other sites More sharing options...
makeshift_theory Posted January 18, 2007 Author Share Posted January 18, 2007 Beautiful, thanks. ;D Link to comment https://forums.phpfreaks.com/topic/34729-breaks-not-showing-up/#findComment-163822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.