Quoting php strings for the overlibmws
DHTML Popup Library

 
maintained by Foteos Macrides at Macrides Web Services
Discuss these examples, seek help, and offer suggestions for
server-side script support via the
overlibmws Support Group.


This document has four examples of php-generated anchors with overlib popups.  The markup for this document is shown below, with the php coding in the salmon-colored area.

This first example uses php's echo "heredoc" form (echo <<<word equivalent to the perl print <<word).  It allows one to avoid problems with nested quotes associated with HTML markup by structuring them essentially as one would for the HTML and javascript (client-side) parsers directly (i.e., as if one didn't have the server-side parser to deal with as well), while still being able to swap in material via variables (and database handlers) defined for the server-side parser.  The example uses a php variable whose raw string value included a single-quote (apostrophe), double-quotes, and reserved HTML characters (open- and close-angle-brackets), as might occur in text retrieved from a database.  The php htmlspecialchars() and addslashes() functions are used, repectively, to covert the double-quotes and angle-brackets to their HTML entities &quot;, &lt; and &gt;, and to backslash escape the single-quote.  This makes the string suitable for use as the lead argument (or as a caption) in an overlib call.
example 1

This second example is like the first, but instead of using htmlspecialchars() and addslashes() it uses the php rawurlencode() function to URL-encode (hex-escape) the string, and sets the DECODE toggle for the overlib call, so that any URL-encoding in the lead argument or caption of an overlib call is decoded automatically for the popup display.  The URL-encoding normally is done server-side for strings that have been fetched from a database and might contain newline characters that would cause pre-mature termination of string parsing by the javascript interpeter if not encoded in the overlib() calls.  Note that care should be taken to avoid using the DECODE command directly on any strings which contain actual URLs with any characters that require their URL-encoding.
example 2

This third example instead uses a series of statements to build up the equivalent anchor and popup content into a variable ($table) for the echo statement (echo $table;).  The text which has an embedded single quote, double-quotes, and angle-brackets is separated into a sub-variable ($txt) that becomes a component of the series, with addslashes(htmlspecialchars($txt)) similarly used to create the HTML entities and to backslash escape the embedded single-quote, but in the course of building up the series.
example 3

This fourth example is like the third but it instead uses rawurlencode($txt) to URL-encode (hex-escape) the string, and sets the DECODE toggle in the overlib call.
example 4

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>overLIB -- php quoting for overlibmws</title>

<script type="text/javascript" src="overlibmws.js"></script>

<script type='text/javascript'>
<!--
OLpageDefaults(WRAP, BASE,2, TEXTPADDING,4, TEXTFONTCLASS,'text12', FGCOLOR,'#ffffee');

paper = new Image();
paper.src = "../image/paper.jpg"
//-->
</script>

<style type='text/css'>
<!--
body {color:#000000; background-color:#ddeeff;}

a {color:#338855;font-weight:bold;}
a:hover {color:#FF00FF;}

.text18 {font-family:Verdana,Arial,sans-serif; font-size:18px;}
.purple18 {font-family:Verdana,Arial,Helvetica,sans-serif;font-size:18px;color:purple;  font-weight:bold;font-style:italic;} .text12 {font-family:Verdana,Arial,sans-serif; font-size:12px;}
-->
</style>
</head>

<body text="#000000" bgcolor="#ddeeff">

<table align="center" width="720"><tr><td class="text18">
Quoting php <a
 href="http://www.zend.com/manual/language.types.string.php"
 onmouseover="return overlib('Consult a terrific reference on php string syntax.',
  CENTER, OFFSETY,20);"
 onmouseout="nd();">strings</a> for <a
 href="./"
 onmouseover="return overlib('Go to the '
  +'<span class=\'purple14\'><i>overlibmws</i></span> '
  +'Download and Test Directory.',
  LEFT, OFFSETX,-10, OFFSETY,20);"
 onmouseout="nd();">overlibmws</a>.
</td></tr><tr><td class="text12">
This document has two examples of php-generated anchors with overlib popups.&nbsp; The markup
for this document is shown below, with the php coding in the salmon-colored area.
<br><br>
This first example uses php's <strong>echo "heredoc"</strong> form
(<span class="navy12">echo &lt;&lt;&lt;word</span> equivalent to the perl
<span class="navy12">print &lt;&lt;word</span>).&nbsp; It allows one to avoid problems with nested quotes associated with HTML markup by structuring them essentially as one would for the HTML and javascript (client-side) parsers directly (i.e., as if one didn't have the server-side parser to deal with as well), while still being able to swap in material via variables (and database handlers) defined for the server-side parser.&nbsp; The example uses a php variable whose raw string value included a single-quote (apostrophe), double-quotes, and reserved HTML characters (open- and close-angle-brackets), as might occur in text retrieved from a database.&nbsp; The php <a
 href="http://www.zend.com/manual/function.htmlspecialchars.php"
 onmouseover="return overlib('Consult a terrific reference on the php '
  +'<strong>htmlspecialchars()</strong> function.', CENTER,VAUTO,OFFSETY,20);"
 onmouseout="nd();">htmlspecialchars()</a> and <a
 href="http://www.zend.com/manual/function.addslashes.php"
 onmouseover="return overlib('Consult a terrific reference on the php '
  +'<strong>addslashes()</strong> function.', CENTER,VAUTO,OFFSETY,20);"
 onmouseout="nd();">addslashes()</a> functions are used, repectively, to covert the double-quotes and angle-brackets to their HTML entities &quot;, &lt; and &gt;, and to backslash escape the single-quote.&nbsp; This makes the string suitable for use as the <a
 href="commandRef.html#content"
 onmouseover="return overlib('Consult the paragraph on the &lt;em&gt;Lead Argument&lt;/em&gt;'
  +'&lt;br&gt;in the '
  +'&lt;span class=\'purple14\'&gt;&lt;i&gt;overlibmws&lt;/i&gt;&lt;/span&gt; '
  +'Command Reference.', CENTER,VAUTO,OFFSETY,20);"
 onmouseout="nd();">lead argument</a> (or as a caption) in an overlib call.
</td></tr></table>
<!-- First php anchor with with raw popup content:
   <strong>1.</strong> "une minuted'int&eacute;rieu" -->
<?php
$tmp = '<strong>1.</strong> "une '."minuted'intérieur".'"';
$txt = addslashes(htmlspecialchars($tmp));
echo <<<EOT
<table border="0" cellspacing="0" cellpadding="0" align="center"><tr>
<td width="80" height="20" class="text12" align="center" bgcolor="#ccddff">
<a href="javascript:void(0);"
onmouseover="return overlib('$tmp', AUTOSTATUS);"
onmouseout="return nd();">example 1</a>
</td></tr></table>

EOT;
?>

<table align="center" width="720"><tr><td class="text12">
<br>
This second example is like the first, but instead of using htmlspecialchars() and addslashes() it uses the php <a
 href="http://www.zend.com/manual/function.rawurlencode.php"
 onmouseover="return overlib('Consult a terrific reference on the php '
  +'<strong>rawurlencode()</strong> function.', CENTER,VAUTO,OFFSETY,20);"
 onmouseout="nd();">rawurlencode()</a> function to URL-encode (hex-escape) the string, and sets the <strong>DECODE</strong> toggle for the overlib call, so that any URL-encoding in the lead argument or caption of an overlib call is decoded automatically for the popup display.  The URL-encoding normally is done server-side for strings that have been fetched from a database and might contain newline characters that would cause pre-mature termination of string parsing by the javascript interpeter if not encoded in the overlib() calls.  Note that care should be taken to avoid using the DECODE command directly on any strings which contain actual URLs with any characters that require their URL-encoding.
</td></tr></table>
<!-- Second php anchor with with raw popup content:
   <strong>2.</strong> "une minuted'int&eacute;rieu" -->
<?php
$tmp = '<strong>2.</strong> "une '."minuted'intérieur".'"';
$txt = rawurlencode($tmp);
echo <<<EOT
<table border="0" cellspacing="0" cellpadding="0" align="center"><tr>
<td width="80" height="20" class="text12" align="center" bgcolor="#ccddff">
<a href="javascript:void(0);"
onmouseover="return overlib('$tmp', DECODE, AUTOSTATUS);"
onmouseout="return nd();">example 2</a>
</td></tr></table>

EOT;
?>

<table align="center" width="720"><tr><td class="text12">
<br>
This third example instead uses a series of statements to build up the equivalent anchor and popup content into a variable (<em>$table</em>) for the echo statement (<span class="navy12">echo $table;</span>).  The text which has an embedded single quote, double-quotes, and angle-brackets is separated into a sub-variable (<em>$txt</em>) that becomes a component of the series, with <strong>addslashes(htmlspecialchars($txt))</strong> similarly used to create the HTML entities and to backslash escape the embedded single-quote, but in the course of building up the series.
</td></tr></table>
<!-- Third php anchor with raw popup content:
   <strong>3.</strong> "une minuted'int&eacute;rieur" -->
<?php
$txt = '<strong>3.</strong> "'."une minuted'intérieur".'"';
$table = '<table border="0" cellspacing="0" cellpadding="0" align="center"><tr>';
$table .= '
<td width="80" height="20" class="text12" align="center" bgcolor="#ccddff">';
$table .= '
<a href="javascript:void(0);"
onmouseover="return overlib(\''.addslashes(htmlspecialchars($txt)).'\', AUTOSTATUS);"
onmouseout="return nd();">example 3</a>';
$table .= ' </td></tr></table>
';
echo $table;
?>

<table align="center" width="720"><tr><td class="text12">
<br>
This fourth example is like the third but it instead uses <strong>rawurlencode($txt)</strong> to
URL-encode (hex-escape) the string, and sets the <strong>DECODE</strong> toggle in the overlib call.
</td></tr></table>
<!-- Fourth php anchor with raw popup content:
   <strong>4.</strong> "une minuted'int&eacute;rieur" -->
<?php
$txt = '<strong>4.</strong> "'."une minuted'intérieur".'"';
$table = '<table border="0" cellspacing="0" cellpadding="0" align="center"><tr>';
$table .= '
<td width="80" height="20" class="text12" align="center" bgcolor="#ccddff">';
$table .= '
<a href="javascript:void(0);"
onmouseover="return overlib(\''.rawurlencode($txt).'\', DECODE, AUTOSTATUS);"
onmouseout="return nd();">example 4</a>';
$table .= ' </td></tr></table>
';
echo $table;
?>

</body>
</html>

See an additional example that uses php and mysql database content with overlibmws.


This document uses overlibmws and its commands


Copyright Foteos Macrides
  2002-2010.
  All rights reserved.