Weird new lines....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imananimeaddict
Forum Newbie
Posts: 9
Joined: Wed Mar 03, 2010 2:06 pm

Weird new lines....

Post 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:
Last edited by Benjamin on Tue Mar 30, 2010 1:00 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Weird new lines....

Post by AbraCadaver »

Most escape sequences are only interpreted when inside double quotes, so you are not replacing the newline.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
imananimeaddict
Forum Newbie
Posts: 9
Joined: Wed Mar 03, 2010 2:06 pm

Re: Weird new lines....

Post by imananimeaddict »

yay!!! thank you !
Post Reply