Click to See Complete Forum and Search --> : Weird new lines!


apricot_13
March 30th, 2010, 01:01 PM
I'm having a problem getting my data to display correctly to go into a googlemap field.

My problem is this sentence:

Worthington Manor

A seventeenth century...<br />

The information comes from a textbox which is then put into the database - we use the following encoding things on it:
$description = mysqli_real_escape_string($dbc,trim(stripslashes(strip_tags($_POST['building_description']))));

The field in the database is a varchar.

When it comes to echoing it out on the page we do the folowing - as with the map you can't havw any specialcharacters or new lines. it just needs to be a plain sentence!

ShortenText2(removeliteral($row["description"]));

this displays the sentence I showed you above - which breaks my javascript.

The two functions I have are

function removeliteral($input) {

$placeholders = array('\n', '\r', '\t', '\v', '\f', '\\', '\$', '\"', '#', '$', '%', '&', '@', '.', '?', '£', '+', '=', '-', '_', '?', '\\', '\'', '"', '<br />', '<br>', '&#xd;');
$replacevalues = array('');
$input = str_replace($placeholders, $replacevalues, $input);

return $input;

}

and

function ShortenText2($text) {
// number of characters to display
$chars = 50;
$text = $text." ";
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}



I've removed the \n but it still says its on a new line!

the code I'm using to echo this out is the following:
echo $description[$x];

I just dont understyand!


We put the sentence into an html encoder and it says there is a new line there - but I removed it!

Any help would be really greatl appreciated!!

HanneSThEGreaT
March 31st, 2010, 05:57 AM
Please make use of [PHP] tags, as explained here :

http://www.codeguru.com/forum/showthread.php?t=429282

As to your question :

I'd make use of Regular expressions here

PeejAvery
April 3rd, 2010, 09:43 PM
\n is not the only new line character. There is also \r and \r\n. Are you sure your encoding isn't using one of those instead?