i have a php/html application where i want to add a conditional html tag "title" attribute if a value for "email" exists.
the trouble people usually run into is the escaping of single and/or double quotes, but if u use php's "complex (curly) variable parsing syntax", then u don't have to escape any quotes at all (generally):
<a href="#" <? if($this->data['email'] != '') echo " title='{$this->data['email']}'" ?>>Email</a>
so if "email" is set, then the rendered output for the tag will look like this:
<a href="#" title='example@example.com'>Email</a>
the "title" attribute will most likely be rendered with double quotes (""), not single (''), but for purposes of illustration, i'm showing u the relationship between the php code and the rendered output.
fyi, the "simple syntax" way is like this:
<a href="#" <? if($this->data['email'] != '') echo ' title="'.$this->data['email'].'"' ?>>Email</a>
(gives identical output as "complex" syntax)
IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment