SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    phpLD Fanatic bronze trophy dvduval's Avatar
    Join Date
    Mar 2002
    Location
    Silicon Valley
    Posts
    3,626
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Doublequotes - I need help

    I have a tab delimited file that I'm importing into mySQL and then I'm displaying the fields on the page using PHP. It's been no picnic!

    The main field that causes trouble is the product description which is several hundred characters in length (and I have several hundred products). There is some html in the product description as well.

    I didn't write the import script so I'm not sure how well I would be able to modify it. Is it too late once the quotes are in the text field in mySQL? Or can I still do something about it?

    Basically, I'm outputting the description like this:
    echo $product_desc;

    Should I give up and go back to writing Cold Fusion or can someone please help me? I'll do almost anything.

  2. #2
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    phpLD Fanatic bronze trophy dvduval's Avatar
    Join Date
    Mar 2002
    Location
    Silicon Valley
    Posts
    3,626
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It didn't seem to help. I'm assuming I would have needed to use addslashes BEFORE the data was inserted into mySQL.

    I'm using the solution offered by Gumball here:
    http://forums.devshed.com/archive/5/2003/01/2/49679
    I'm not exactly clear on how I would need to utilize addslashes in this example. Am I in over my head or is there a simple solution?

    Here is the page I have so far:
    http://www.dancedresser.net/shop/tryagain.php
    When you click on the links, it takes you to the description. Some work and some don't, but I'm not sure of the reason. I've actually outputted one description without using addslashes and one using it.

  4. #4
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dvduval
    It didn't seem to help. I'm assuming I would have needed to use addslashes BEFORE the data was inserted into mySQL.
    That would be ideal, but all is not lost.
    This example was given at php.net:
    PHP Code:
    [font=Courier New]$result mysql_query("SELECT * FROM sendbuf where flagsend = 0 ",$connin);

    while (
    $myrow 
    mysql_fetch_array($result))

    {

    $pic1_data addslashes($myrow ["pic1_data"]) ; 

    }[/
    font
    You could try that and then echo the variable.
    Am I in over my head or is there a simple solution?
    The solution is always simple - lol. It's the process of finding it that is complex.

    Every time I have to deal with double quotes it's like I'm starting from zero. What worked last time doesn't work this time for this problem etc.
    If addslashes() doesn't work for you, you might try htmlspecialchars() .

    Edit: Looks like addslashes is giving you a problem rather than solving one. I've looked at the first 5 descriptions and the first one looks good!

    OK. This one:
    "A standard T-bar shoe with a closed toe. The heel is 2"" slim. Made by International in England. Available in (02) black leather. Order 2 sizes smaller than your American Size. "
    Is this what you're talking about? So, the quotes aren't causing a problem with the script, or breaking up your text, you just want to get rid of the leading and trailing quotes in the output?
    Last edited by Herbster; May 16, 2003 at 21:19.

  5. #5
    phpLD Fanatic bronze trophy dvduval's Avatar
    Join Date
    Mar 2002
    Location
    Silicon Valley
    Posts
    3,626
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Herbster, that is EXACTLY what I used:
    Code:
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $product_desc = $row["product_desc"]; 
    $product_desc2  = addslashes($row  ["product_desc"]);
    and then later:
    Code:
    echo $product_desc2;
    Did I follow the example correctly?

  6. #6
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, you did. And I apologize. I completely misunderstood your problem.

    More than one way to do it, but...

    To get rid of the leading double quote, if any:
    PHP Code:
    if (strpos([font=Courier]$product_desc,"\"" )==1){[/font]
    [
    font=Courier]$product_desc substr($product_desc,1);[/font]
    [
    font=Courier]} [/font
    if (strpos($product_desc,"\"")==1){
    $product_desc = substr($product_desc,1);
    }

    To get rid of the trailing double quote, if any:
    PHP Code:
    [font=Courier]$product_desc strrev($product_desc);[/font]

    if (
    strpos([font=Courier]$product_desc,"\"" )==1){[/font]
    [
    font=Courier]  $product_desc substr($product_desc,1);[/font]
    [
    font=Courier]} [/font]

    [
    font=Courier]$product_desc strrev($product_desc);[/font
    $product_desc = strrev($product_desc);

    if (strpos($product_desc,"\"" )==1){
    $product_desc = substr($product_desc,1);
    }

    $product_desc = strrev($product_desc);

    Double quotes for inches - they are doubled. Is that an escape technique held over from another database?

    If so:
    PHP Code:
    [font=Courier]$product_desc str_replace("\"\"","\"",$product_desc);[/font
    $product_desc = str_replace("\"\"","\"",$product_desc);

    I very much dislike this editor. Font tags don't belong in there...

  7. #7
    phpLD Fanatic bronze trophy dvduval's Avatar
    Join Date
    Mar 2002
    Location
    Silicon Valley
    Posts
    3,626
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That worked! I'm still displaying some quotes at the beginning and end of some descriptions, but the html and inch quotes are now working. Thanks a million...maybe I'll figure out PHP after all.

  8. #8
    The short answer is yes... Herbster's Avatar
    Join Date
    Oct 2001
    Location
    Bay City, Oregon
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dvduval
    That worked! I'm still displaying some quotes at the beginning and end of some descriptions, but the html and inch quotes are now working. Thanks a million...maybe I'll figure out PHP after all.
    Which ones still show quotes? I'll check the text in a hex editor to see if there is something else that can be done. Like, are there leading and trailing spaces, too? Could try trim($product_desc) before parsing the double quotes.

    PHP is great fun. Seems there are always perplexing problems, but PHP offers the tools to solve them in a number of different ways.

  9. #9
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Herbster
    PHP is great fun. Seems there are always perplexing problems, but PHP offers the tools to solve them in a number of different ways.
    ... and there is usually some bright lad/lass that will help you with it if you don't know how.


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
  •