Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting & to & for XML in PHP

Tags:

php

xml

I am building a XML RSS for my page. And running into this error:

error on line 39 at column 46: xmlParseEntityRef: no name

Apparently this is because I cant have & in XML... Which I do in my last field row...

What is the best way to clean all my $row['field']'s in PHP so that &'s turn into &

like image 531
ian Avatar asked Oct 15 '25 04:10

ian


2 Answers

Use htmlspecialchars to encode just the HTML special characters &, <, >, " and optionally ' (see second parameter $quote_style).

like image 165
Gumbo Avatar answered Oct 16 '25 23:10

Gumbo


It's called htmlentities() and html_entity_decode()

like image 31
Ólafur Waage Avatar answered Oct 16 '25 23:10

Ólafur Waage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!