Jump to content

Breaks not showing up


makeshift_theory

Recommended Posts

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("&" => "&amp;",
"\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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.