Page 1 of 1

Weird new lines....

Posted: Tue Mar 30, 2010 12:59 pm
by imananimeaddict
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

Code: Select all

function removeliteral($input) {

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

}
and

Code: Select all

 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 understand!


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!! :banghead:

Re: Weird new lines....

Posted: Tue Mar 30, 2010 1:08 pm
by AbraCadaver
Most escape sequences are only interpreted when inside double quotes, so you are not replacing the newline.

Re: Weird new lines....

Posted: Tue Mar 30, 2010 1:21 pm
by imananimeaddict
yay!!! thank you !