•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,536 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,089 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 705 | Replies: 9
![]() |
| |
•
•
Join Date: Apr 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
I'm trying to get some post data formatted for output on a browser and I can't use pre tags becuase the width attribute isn't supported anymore and it doesn't really work. I also need to break up a word if it's over 80 characters long, if someone's been a pillock basically and posted some crap. However, if you could advise on that it would be great, but the real problem is I can't seem to replace the newlines with brs. Here's the code:
Any help?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LOL it looks like the owner of this site needs some help with the formatting too!
$bad = array("<",">","<",">");
$good = array("[","]","[","]");
preg_replace( "/[\r\n]+/" , "<br />" , str_replace( $bad , $good , mysql_real_escape_string( $_POST['post'] ) ) )Any help?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LOL it looks like the owner of this site needs some help with the formatting too!
> but the real problem is I can't seem to replace the newlines with brs.
Honey why ain't you using nl2br();
>I also need to break up a word if it's over 80 characters long
Find out what the max no. of letters you can have per line. Then perform tricks using the modulus operator. You understand that honey?
>LOL it looks like the owner of this site needs some help with the formatting too!
She's too lazy to fix that.
Honey why ain't you using nl2br();
>I also need to break up a word if it's over 80 characters long
Find out what the max no. of letters you can have per line. Then perform tricks using the modulus operator. You understand that honey?
>LOL it looks like the owner of this site needs some help with the formatting too!
She's too lazy to fix that.
... the hat of 'is this a cat in a hat?'
•
•
Join Date: Apr 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
Changed it to
but still no <br /> tags are ending up in the database. The POST is coming from a textarea, if this helps...
Also, the modulus thing, no I don't get. Is there a way to print a string one letter at a time in a for loop and you go
nl2br(str_replace($bad,$good,mysql_real_escape_string($_POST['Post'])))
Also, the modulus thing, no I don't get. Is there a way to print a string one letter at a time in a for loop and you go
if($iterator % 80 == 0) {echo "<br />"}•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
•
•
Join Date: Apr 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
$qry = "SELECT Post FROM POST WHERE ID = " . $_GET['threadID']; $rset = mysql_query($qry); $row = mysql_fetch_array($rset); echo $row[0];
I haven't really looked at the problem with a word being too long yet. I assume the below is the fix:
for($i=0;$i<strlen($row[0]);$i+=80){
echo substr($row[0],$i,80);
echo "\n";
}However, it's problem that passing the post from a textarea to nl2br() isn't adding the br tags that's really getting me depressed.
•
•
Join Date: Apr 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
I read this on a forum somewhere:
Either your clean_var or mysql_less_safe functions are probably escaping the \r and \n characters using addslashes or mysql_real_escape_string. If that's the case, you'd need to do a str_replace for "\\\r\\\n" (or something like that I've never really learned how to count up all the slashes -- echo out the $new_course_poc to see what they are being turned into)
I guess this means that you just need to do the nl2br() after the tags are removed and before the mysql_escape_string() is called. I'm at work at the moment so I can't test my theory, but maybe is the solution.
Either your clean_var or mysql_less_safe functions are probably escaping the \r and \n characters using addslashes or mysql_real_escape_string. If that's the case, you'd need to do a str_replace for "\\\r\\\n" (or something like that I've never really learned how to count up all the slashes -- echo out the $new_course_poc to see what they are being turned into)
I guess this means that you just need to do the nl2br() after the tags are removed and before the mysql_escape_string() is called. I'm at work at the moment so I can't test my theory, but maybe is the solution.
•
•
Join Date: Apr 2006
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
Also, you'd need something like:
In that fix I put up to stop you wrapping half way through a line for which the previous line had a break.
if (instr("<br />", substr($row[0],$i,80))){
$i+= 80-(instr("<br />",substr($row[0],$i,80))+5);
}![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Regular Expressions (VB.NET)
- Parsing a log file using regular expressions (C#)
- Regular Expressions (C#)
- Regular Expressions (Computer Science and Software Design)
- Regular Expressions (C#)
- Regular Exp (Python)
- mod_rewrite: help with regular expressions (Linux Servers and Apache)
- matching regular expressions (Java)
- Zend PHP Certification (PHP)
Other Threads in the PHP Forum
- Previous Thread: session variable error
- Next Thread: Simple article manager script in PHP I wrote



Hybrid Mode