Reputation: 11201
I'm using domDocument to find html tags.
$mensaje = "Te informamos que la parada <b>Plaza de la Estación</b> está
próxima a vaciarse, el día <b>2013-04-22</b> a las <b>17:34:50</b>.";
$dom = new domDocument('1.0', 'utf8_general_ci');
// load the html into the object ***/
$dom->loadHTML($mensaje);
//discard white space
$dom->preserveWhiteSpace = false;
$nodeList= $dom->getElementsByTagName('b'); // here u use your desired tag
$items = array();
for($i=0; $i < $nodeList->length; $i++) {
$node = $nodeList->item($i);
$items[] = trim($node->nodeValue);
}
var_dump($items);
$mensaje is extracted from my database, this field is utf8_general_ci, but it fails:
array(3) {
[0]=> string(21) "Plaza de la Estación"
[1]=> string(10) "2013-04-22"
[2]=> string(8) "17:34:50" }
The first element has bad encoding.
How can I solve this?
Upvotes: 0
Views: 63
Reputation: 6966
The enconding you've specified when creating the DOMDocument
object isn't valid for XML documents. utf8_general_ci
is a MySQL enconding. Replace it by UTF-8
.
Also make sure that the encoding of your php file is set to UTF-8.
Upvotes: 1