vanroojdotcom Posted November 15, 2007 Share Posted November 15, 2007 I'm sorry that my previous thread was a little misleading.... I'd like to explain again my request. I'm pulling text from a database (MySQL) and I'm using the nl2br () function to convert the line breaks DESCRIPTION="<?php echo nl2br($row_rsttheJobResults['description']); ?>" This creates the following example "A new line will be created soon < 'br' > and here it is." However the website that receives this cannot accept the characters < and > So I want to convert this "< br >" into this "<p>" Could anybody help me add to the nl2br () function to convert the < br > tags? * the spaces between the < and br are there because they won't show in the message otherwise Many thanks Vanrooj Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 15, 2007 Share Posted November 15, 2007 You need to use the htmlentities() function www.php.net/htmlentities Quote Link to comment Share on other sites More sharing options...
vanroojdotcom Posted November 15, 2007 Author Share Posted November 15, 2007 Hi there – OK I've tried this DESCRIPTION="<?php echo htmlentities($row_rsttheJobResults['description']); ?>" The problem is I'm send this in an HTML form to a recruitment site and this <p> has to be physically visible in the text. So if I open my text area form and submit it when I've physically pasted <p> into the line breaks it works - but using htmlentities does not show in the text. Using nl2br () actually shows < br / > in the copy but their system will not accept the < and the > characters. So I need to use a function that 1) shows the < br > characters 2) converts them to <p> (see how I've changed the b to p) I found this function <?php function pc_text2html($s) { $s = htmlentities($s); $grafs = split("\n\n",$s); for ($i = 0, $j = count($grafs); $i < $j; $i++) { // Link to what seem to be http or ftp URLs $grafs[$i] = preg_replace('/((ht|f)tp:\/\/[^\s&]+)/', '<a href="$1">$1</a>',$grafs[$i]); // Link to email addresses $grafs[$i] = preg_replace('/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i', '<a href="mailto:$1">$1</a>',$grafs[$i]); // Begin with a new paragraph $grafs[$i] = '<p>'.$grafs[$i].'</p>'; } return implode("\n\n",$grafs); } ?> Which converts the < br > tag to < p > but I'm not experienced enough to then convert the < and the > to < and > Thanks Vanrooj Quote Link to comment Share on other sites More sharing options...
vanroojdotcom Posted November 15, 2007 Author Share Posted November 15, 2007 So in effect the feed should look like this <FILE> <ADVERT> <ROOT LOADTYPE="A"> <JOB FEEDID="ResCrAdXML" LIVEDAYS="1" UNIQUEJOBNO="142VS" DESCRIPTION="This is a test for the paragraphs. This is a test for the paragraphs. This is a test for the paragraphs. This is a test for the paragraphs. This is a test for the paragraphs <p> This is a test for the paragraphs. This is a test for the paragraphs. This is a test for the paragraphs.This is a test for the paragraphs <p> " TITLE="This is a test for the paragraphs" REGION="East Anglia" RATEUNIT="a" SALARYMIN="5" SALARYMAX="6" SALARYDESC="" INTERNALJOBREF="142VS" </ROOT> </ADVERT> </FILE> Because the htmlentities() function does not show the characters in the copy the website does not put them in the text. Many thanks Vanrooj Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.