|
-
March 30th, 2010, 01:01 PM
#1
Weird new lines!
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
PHP Code:
function removeliteral($input) {
$placeholders = array('\n', '\r', '\t', '\v', '\f', '\\', '\$', '\"', '#', '$', '%', '&', '@', '.', '?', '£', '+', '=', '-', '_', '?', '\\', '\'', '"', '<br />', '<br>', '
');
$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!!
Last edited by HanneSThEGreaT; March 31st, 2010 at 05:54 AM.
Reason: Added [PHP] tags.
-
March 31st, 2010, 05:57 AM
#2
Re: Weird new lines!
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
-
April 3rd, 2010, 09:43 PM
#3
Re: Weird new lines!
\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?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|