A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearphp quoting problem - page 1
User InfoPosts
php quoting problem#1
I have this PHP code

echo '<a href="#" onclick="updateByQuery(\'Layer3\', ' . json_encode($query) . ');">Link 1</a>';


which generates a link like this:

<a href="#" onclick="updateByQuery('Layer3', "Ed Hardy");">Link 1</a><li>Link 2</li>


Causing the javascript to not be called. How would I make it generate single quotes around the result of $query, in this case ed hardy?

posted date: 2008-12-12 09:22:00


Re: php quoting problem#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-12 09:22:01


Re: php quoting problem#3
Try to do the reverse... use single quotes for html, and double quotes for javascript. That's how we do that in fact.

posted date: 2008-12-12 09:24:00


Re: php quoting problem#4
echo "<a href='#' onclick='updateByQuery(\"Layer3\", " . json_encode($query) . ");'>Link 1</a>";

posted date: 2008-12-12 09:26:00


Re: php quoting problem#5
Fixed the formatting for you - you need to select it and hit the Code Sample (binary icon) button

posted date: 2008-12-12 09:31:00


Re: php quoting problem#6
I am unsure how to modify the echo line to sue both, as I must have double quotes around the JavaScript function. Do I just escape them?

posted date: 2008-12-12 09:36:00


Re: php quoting problem#7
echo "<a href='#' onclick='updateByQuery(\"Layer3\", \"" . json_encode($query) . "\");'>Link 1</a>";This produces:<a href='#' onclick='updateByQuery("Layer3", "Ed Hardy");'>Link 1</a>

posted date: 2008-12-12 09:48:00


Re: php quoting problem#8
@Roborg; this produces: <a href='#' onclick='updateByQuery("Layer3", Ed Hardy);'>Link 1</a> Notice there are no quotes around Ed Hardy.

posted date: 2008-12-12 10:25:00


Re: php quoting problem#9
Quotes are a problem with inline handlers. As RoBerg says, you need to use htmlentities in the text.Another way around it is to use hook methods and anonymous functions, rather than inline handlers.echo '<a href="#" id="link_1">Link 1</a><script>document.getElementById("link_1").onclick = function() { updateByQuery("Layer3", '.json_encode($query).'); }</script>';

posted date: 2008-12-14 16:06:00


Re: php quoting problem#10
Not valid XHTML, but I won't -1 because he wants HTML it seems.

posted date: 2008-12-14 16:09:00


Re: php quoting problem#11
@Joshxtothe4, &quot; is converted to " by the browser before it reaches the Javascript parser.

posted date: 2008-12-14 16:14:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.