Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

single and double quotes

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
hello guy's,

I think I'm losing it. I have the following line in my code:

Code:
$sOut .= "<li><a href=\"#\" onclick=\"javascript:document.getElementById('search').value='".$sGemeente."';document.getElementById('searchbox').style.display = 'none';\">".$sGemeente."</a></li>";

This works fine. But sometimes the $sGemeente can be something like this => 's blabla ... But than it doesn't work anymore 'cause of the '. Can I restyle the line above so $sGemeente can start with a '?
I know it has to do with this value='".$sGemeente."' ...

thanks!

The One And Only KryptoS
 
you need to cleanse the variable a bit first. When dealing with js and html in big blocks it is often also easier to use the heredoc syntax.

Code:
<?php
function jsVarClean($var){
	return str_replace("'", "\'", $var);
}
$_sGemeente = jsVarClean($_sGemeente);
$sOut .= <<<HTML
<li>
	<a href="#" onclick="javascript:document.getElementById('search').value='$_sGemeente'; document.getElementById('searchbox').style.display = 'none';>
		$sGemeente
	</a>
</li>
HTML;
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top