htmlentites

This function is identical to htmlspecialchars() in all ways, except with htmlentites(), all characters which have HTML character entity equivalents are translated into these entities.

If you're wanting to decode instead (the reverse) you can use html_entity_decode().

Example:

echo htmlentities("&"); // &

if your directly doing this in the browser you should be able to use:

encodeURIComponent(string input);

Example:

encodeURIComponent($.trim($("input[name=t-tim_rendered-"+id+"]").val().toString()));
Answer from RobertPitt on Stack Overflow
🌐
SitePoint
sitepoint.com › php
How to escape ampersand in PHP? - PHP - SitePoint Forums | Web Development & Design Community
December 30, 2005 - I know just enough about PHP to be dangerous. I am good with HTML and I do web design for a PHP programmer. So of course there are times when the HTML and the PHP have to play nicely together. I’m also a stickler when it comes to web standards compliance. The problem is that any page containing links with the “&” sign will not validate.
Discussions

How do I escape an ampersand in a url? - PHP Coding Help - PHP Freaks
I'd like to use file_get_contents to read a url, but when the url contains an ampersand (for the second passed arg) everything after the ampersand (including the ampersand itself) is ignored. More on forums.phpfreaks.com
🌐 forums.phpfreaks.com
April 14, 2008
php - Escape ampersand character - Stack Overflow
But i don't know how to escape this ampersand... I looked to other posted questions here but nothing seems to work.. ... The solution was posted as similar is not working for me... ... More on stackoverflow.com
🌐 stackoverflow.com
string - PHP Escape ampersand when printing - Stack Overflow
In my flash website, I use PHP to store a bulk of text retrieved from a Database in the variable $trunk, and then through PHP I print $trunk and catch it using my flash program. The problem is, More on stackoverflow.com
🌐 stackoverflow.com
April 26, 2017
php - How to escape ampersand symbol - Stack Overflow
I want to escape ampersand symbol. because, it assume another parameter.. I want pass all this below message to java web service parameter.. That ampersand symbol cut the message.. Please anyone he... More on stackoverflow.com
🌐 stackoverflow.com
May 8, 2015
🌐
PHP Freaks
forums.phpfreaks.com › php coding › php coding help
How do I escape an ampersand in a url? - PHP Coding Help - PHP Freaks
April 14, 2008 - I'd like to use file_get_contents to read a url, but when the url contains an ampersand (for the second passed arg) everything after the ampersand (including the ampersand itself) is ignored.
🌐
Stack Overflow
stackoverflow.com › questions › 41586649 › escape-ampersand-character
php - Escape ampersand character - Stack Overflow
But i don't know how to escape this ampersand... I looked to other posted questions here but nothing seems to work.. ... The solution was posted as similar is not working for me... ... <?php for($i=1; $i <= 9; $i++){ ${'content' .
🌐
PHP
php.net › manual › en › function.htmlspecialchars.php
PHP: htmlspecialchars - Manual
<?php declare(strict_types=1); $text = 'ampersand(&amp;), double quote(&quot;), single quote(&apos;), less than(&lt;), greater than(&gt;), numeric entities(&#x26;&#x22;&#x27;&#x3C;&#x3E;), HTML 5 entities(&plus;&comma;&excl;&dollar;&lpar;&ncedil;&euro;)'; $result3 = htmlspecialchars( $text, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8', /*double_encode*/false ); $result4 = htmlspecialchars( $text, ENT_NOQUOTES | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8', /*double_encode*/false ); $result5 = htmlspecialchars( $text, ENT_NOQUOTES | ENT_XHTML | ENT_SUBSTITUTE, 'UTF-8', /*double_encode*/false ); $result6 = html
🌐
Stack Overflow
stackoverflow.com › questions › 24979478 › php-escape-ampersand-when-printing
string - PHP Escape ampersand when printing - Stack Overflow
April 26, 2017 - In my flash website, I use PHP to store a bulk of text retrieved from a Database in the variable $trunk, and then through PHP I print $trunk and catch it using my flash program. The problem is, sometimes this bulk of text retrieved from the Database will contain an Ampersand "&", and when using print "$trunk" It'll mess up very badly and result in not printing anything at all, which causes errors in the flash program. Using mysql_real_escape_string($trunk) won't work, because that function doesn't escape ampersands, and using html_entity_decode didn't do anything at all.
Find elsewhere
🌐
O'Reilly
oreilly.com › library › view › programming-php-3rd › 9781449361068 › ch04s05.html
Encoding and Escaping - Programming PHP, 3rd Edition [Book]
February 15, 2013 - Special characters in HTML are represented by entities such as &amp; and &lt;. There are two PHP functions that turn special characters in a string into their entities: one for removing HTML tags, and one for extracting only meta tags. The htmlentities() function changes all characters with HTML entity equivalents into those equivalents (with the exception of the space character). This includes the less-than sign (<), the greater-than sign (>), the ampersand (&), and accented characters. ... The entity-escaped version (&uuml;—seen by viewing the source) correctly displays as ü in the rendered web page.
Authors: Rasmus LerdorfKevin TatroePeter MacIntyre
Published: 2013
Pages: 538
🌐
SitePoint
sitepoint.com › php
How to escape ampersand in PHP? - #1000 - PHP - SitePoint Forums | Web Development & Design Community
December 30, 2005 - I know just enough about PHP to be dangerous. I am good with HTML and I do web design for a PHP programmer. So of course there are times when the HTML and the PHP have to play nicely together. I’m also a stickler when it comes to web standards compliance. The problem is that any page containing links with the “&” sign will not validate.
🌐
W3Schools
w3schools.com › php › func_string_htmlspecialchars.asp
PHP htmlspecialchars() Function
affected_rows autocommit change_user character_set_name close commit connect connect_errno connect_error data_seek debug dump_debug_info errno error error_list fetch_all fetch_array fetch_assoc fetch_field fetch_field_direct fetch_fields fetch_lengths fetch_object fetch_row field_count field_seek get_charset get_client_info get_client_stats get_client_version get_connection_stats get_host_info get_proto_info get_server_info get_server_version info init insert_id kill more_results multi_query next_result options ping poll prepare query real_connect real_escape_string real_query reap_async_query refresh rollback select_db set_charset set_local_infile_handler sqlstate ssl_set stat stmt_init thread_id thread_safe use_result warning_count PHP Network
🌐
Quora
quora.com › Why-should-the-ampersand-character-be-HTML-escaped
Why should the '&' (ampersand) character be HTML escaped? - Quora
Answer (1 of 3): The problem you're describing is called double escaping, and to understand that, you need to know what an escape sequence is in the first place. An escape sequence in this space (string encoding specifically) defines a mechanism to encode something that you wouldn't normally be a...
🌐
SitePoint
sitepoint.com › php
URL ampersand issue - PHP - SitePoint Forums | Web Development & Design Community
November 30, 2010 - Hi, I think this is the first time I’ve encountered such weird issue. I have a string store in the data like so “sale_&_marketing” when I retrieve out the data and embed it to a link as a parameter and click on it, I get the following array: var_dump($_GET); array(2) { [“pathInfo”]=> string(18) “/sales_” [“_marketing”]=> string(0) “” } It seems like breaking out the ampersand into 2?? :eek:
🌐
Tek-Tips
tek-tips.com › home › forums › software › programmers › web development › php
passing an ampersand | Tek-Tips
May 25, 2009 - I had another look at what I was doing and it all makes sense now... it was changing the ambersand in the href above that was causing me problems and made me think that I needed to use a urldecode... once I changed the &amp; back to & it all worked fine... what you said about PHP interpreting the string was kind of what everything i read was saying, I was just a bit slow in picking that up... The Bird from Down Under- Bigbird 3156 ... Click to expand... Hmm... You mean this red ampersand ?
🌐
Htmlhelp
forums.htmlhelp.com › index.php
To escape or not to escape an ampersand - HTMLHelp Forums
April 8, 2008 - HTMLHelp.com | HTML Reference | CSS Reference | FAQs | Validator · Forums | Rules | Members | Search | Help