javascript: problem in with URL wich contains quote/apostrophe

Posted on 2011-10-20
Last Modified: 2012-05-12
Hi, I've got problem with URL containing apostrophe (quote)

tried different ways but no one is working....

the following code is in PHP and javascript

the problem is that when $tabCol2[0] variable contains quote it does not open anything.....

thanks for your help.
function openwindow(arg1,arg2,arg3)

<a  href="javascript:openwindow('<?echo"modifier/enduser.php?type=enduser&pDevis=$pDevis&tmp=1&pEnd_user=$pEnduser&oldEndUser=".urlencode("$tabCol2[0] (CT:$pEnduser)");?>','','toolbar=no,resize=yes,location=no,directories=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,width=1000,height=300,top=50,left=50')" >zzzzzzzzzz</a>

Open in new window

Question by:bruno_boccara
    LVL 21

    Expert Comment

    by:Kim Walker
    Try escaping the quote with a backslash (\").
    LVL 21

    Expert Comment

    by:Kim Walker
    Sorry, I don't think that'll work. Try using the character entity &quot;
    LVL 107

    Expert Comment

    by:Ray Paseur
    You might want the PHP function urlencode()
    LVL 81

    Accepted Solution

    try this :

    <a  href="javascript:openwindow('<?echo"modifier/enduser.php?type=enduser&pDevis=$pDevis&tmp=1&pEnd_user=$pEnduser&oldEndUser='+encodeURIComponent(\"". addslashes($tabCol2[0] (CT:$pEnduser)) . "\"));?>','','toolbar=no,resize=yes,location=no,directories=no,status=no,menubar=no,scrollbars=auto,copyhistory=no,width=1000,height=300,top=50,left=50')" >zzzzzzzzzz</a>

    Open in new window


    Author Comment

    no one of these solution are working.....
    getting crazy.
    LVL 21

    Assisted Solution

    by:Kim Walker
    Try letting javascript encode the uri.
    function openwindow(arg1,arg2,arg3)

    Open in new window

    You can also try converting the quote to character entities in PHP.
    htmlspecialchars(urlencode("$tabCol2[0] (CT:$pEnduser)"),ENT_QUOTES)

    Open in new window

    If that doesn't work, can you expound on the problem? Does a blank window open? Does a window open at all? Are the query string values corrupted when it gets to the PHP processor? Is a javascript error being invoked? What version of PHP are you using?

    Can you post an example?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now