Thread: Php/mysql help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    156
    Rep Power
    13

    Php/mysql help


    Hi

    on my website I have products and in the product description I am getting \n\r showing after each line where as it should be hiding it for example see below

    16 ml in each bottle\r\nLuxury Style Bottles\r\nAvailable in White, Clear, Peach, Purple, Red, Pink and Black

    it should be like below

    16 ml in each bottle
    Luxury Style Bottles
    Available in White, Clear, Peach, Purple, Red, Pink and Black

    Any ideas as not sure if it is the php file or the database causing the issue

    to see the issue go here - http://www.worldofcosmetics.co.uk/pr...roducts_id=169

    Thank you in advance

    Ian
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,493
    Rep Power
    594
    If you look at the source you will see you actually have a double backslash. That means the \\r\\n is escaped and taken as a literal. In any case that will not render correctly in HTML. If you query the database do those characters show up there? In any case you can get rid of them by running the string through preg_replace. Something like:
    PHP Code:
    preg_replace('/\\r\\n/',"",$string); 
    Note the use of single quotes to prevent the backslashes from being used as escape characters.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    156
    Rep Power
    13
    Hi gw1500se thank you so much for the reply

    When I looked in the database for the new item I added that has the \n\r after each line, it does show in the database

    so is it best to run preg_replace('/\\r\\n//',$string); in the database or is it in a php file
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    something caused these messed up control sequences, so you should first look for the source of the problem. I guess it's some home-made newline conversion function that uses the string "\\r\\n" instead of "\r\n". Just follow the process of how the original text input is saved into the database.

    When you've corrected the code, you have to repair your database with the replace function.

IMN logo majestic logo threadwatch logo seochat tools logo