SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    I wondered if anybody knows how to remove quotes from a variable in php. Obviously the usual method won't work as this results in double quotes, i.e:

    if (strstr($variable, """")):
    $name = str_replace("""", "", $variable);
    endif;

    Thanks if any1 can help,

    Regards,

    Jason

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woops sorry - $name should be $variable

    Regards,

    Jason

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    $variable = ereg_replace('"', "", $variable);

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Freddy - this basically works.

    However, do you or anyone else know why when trying to clear up user input that has been entered into a form, php only clears up most of it and not all?

    For example, using stripslashes to remove all slashes from a variable after a user has submitted quotation marks ("") into a form.

    The quotation marks cause the variable being parsed to contain slashes.

    e.g. a user enters """""" into a form , the variable returned to php becomes \"\"\"\"\"

    So if I only wanted the quotation marks, I thought the stripslashes function would achieve this.
    However, it only removes 3 of the 5 slashes leaving 2 unwanted slashes behind.

    Any ideas why this is please gentlemen and women?

    Thanks very much if you could help me solve this.

    Regards,

    Jason


  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Jason,

    That hasn't been my experience. Try the following sample script:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>&lt;HTML&gt;
    &lt;HEAD&gt;
    &lt;TITLE&gt;StripSlashes test &lt;/TITLE&gt;
    &lt;/HEAD&gt;
    &lt;BODY&gt;
    &lt;? if (!$submit): ?&gt;
    &lt;FORM ACTION=&lt;? echo $PHP_SELF; ?&gt;&gt;
    &lt;INPUT NAME=entry TYPE=text&gt;&lt;INPUT TYPE=SUBMIT NAME=submit&gt;
    &lt;/FORM&gt;
    &lt;? else: ?&gt;
    Submitted: &lt;? echo $entry; ?&gt;&lt;BR&gt;
    Stripslashed: &lt;? echo stripslashes($entry); ?&gt;
    &lt;? endif; ?&gt;
    &lt;/BODY&gt;
    &lt;/HTML&gt;[/code]

    If you type """" into the entryfield and submit, the following is displayed here:

    Submitted: \"\"\"\"
    Stripslashed: """"


    What do you get?

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help Kevin. Clearly something else in my script is causing slashes to remain.

    Back to the drawing board - cheers mate....

    Regards,

    Jason


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
  •