SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    possible php/form problem (but not sure)

    Hi, i am having some problems implementing the tool tip as shown here http://www.walterzorn.com/tooltip/tooltip_e.htm

    Apologies if this is in the wrong section, i'm not sure if the problem is related to JS, html or php.

    To give an overview i am using the tooltip to display the results of a db query. The input used is a
    Code HTML4Strict:
    <textarea name="details"></textarea>
    . I have used this post function to capture the text:

    Code PHP:
    html_entity_decode($_POST['details'], ENT_QUOTES, "UTF-8")

    and then this function to query the db:

    Code PHP:
    $details = nl2br($row['details']);

    The problem arises when i input data into the text area with line breaks. As you can see from the 2 source codes the one with the line breaks doesnt work.

    This one works as i have NOT inputted any linebreaks into the textarea. (the line breaks you can see are the ones that i have included in the original html).
    Code HTML4Strict:
    <tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='#c6cdff'; Tip('<strong>Details for Custom Order ID# 86</strong><br /><br />Item: Diet Coke<br /><br />Details:<br /><br />I once bought a bottle of diet coke. It was occasionally nice, and sometimes it was not', BALLOON, true, ABOVE, true, DELAY, 1000, WIDTH, 200);" onMouseOut="this.bgColor='#FFFFFF'; UnTip();">

    And this is the source code from the one that had line breaks in the original text area input, and DOES NOT work.
    Code HTML4Strict:
    <tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='#c6cdff'; Tip('<strong>Details for Custom Order ID# 88</strong><br /><br />Item: Pepsi Max<br /><br />Details:<br /><br />Once i bought a bottle of pepsi max. <br />
    <br />
    somtimes it was nice,<br />
    <br />
    sometimes it was not.', BALLOON, true, ABOVE, true, DELAY, 1000, WIDTH, 200);" onMouseOut="this.bgColor='#FFFFFF'; UnTip();">

    All the line breaks that you can see after
    Code HTML4Strict:
    Details:<br /><br />
    have been inputted via the <textarea> eg: the input textarea would look something like this:

    "Once i bought a bottle of pepsi max.

    somtimes it was nice,

    sometimes it was not."

    I'm not sure if this is a php or html or JS issue. Any help and guidance would be greatly appreciated.

    Rob

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Replace this:
    PHP Code:
    $details nl2br($row['details']); 
    With this to also remove the line breaks:
    PHP Code:
    $details str_replace(array("\n""\r"), ""nl2br($row['details'])); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats perfect thank you!

    Can i ask though what does the \n and \r mean?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    \n and \r are escape sequences if used in a php string, to produce a new line(line feed) and carriage return character.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •