Jump to content

Convert text from database for HTML


vanroojdotcom

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

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.