CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    5

    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>''&#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!!
    Last edited by HanneSThEGreaT; March 31st, 2010 at 05:54 AM. Reason: Added [PHP] tags.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Weird new lines!

    Please make use of &#091;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

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    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
  •  





Click Here to Expand Forum to Full Width

Featured