Here is a snippet of the code I'm trying to understand; in my web design class, I learned that php single quotes ' ' interpret everything literally, as a string. However, in this code:
$kml = array();
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
$kml[] = ' <Document>';
$kml[] = ' <Style id="hitStyle">';
$kml[] = ' <IconStyle id="hitIcon">';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://vkhovanskaya.net/images/glow.png</href>';
$kml[] = ' </Icon>';
$kmlOutput = $kml[5];
print($kmlOutput);
prints: "http://vkhovanskaya.net/images/glow.png"
and I need it to print<href>http://vkhovanskaya.net/images/glow.png</href>
because it's part of
what will be a kml file (I need the markup tags)
开发者_开发技巧What should I be doing to escape the < > from interpretation attempts?
Interpolation from what? A web browser will often try to parse it... but PHP isn't interpolating it, the web browser is. Making sure you are using the right mime-type may help, but some browsers (like IE...) will often try to render everything vaguely like text as HTML.
FWIW, post code like:
$kml[] = '<href>http://vkhovanskaya.net/images/glow.png';
(Click the ? icon for help... transliterating characters makes things hard to read.)
If you really want to ensure a browser displays it, you'll need to escape the <'s as <
Are you displaying this in a browser? If so, view the page source and you should see your XML node as you expect.
If you want the markup to render as readable in an HTML document, use htmlspecialchars or htmlentities
echo htmlspecialchars($kmlOutput);
精彩评论