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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.