Replace special characters UTF-8 PHP DOM -
i have code:
$strhtml = file_get_contents('05001400300320100033100.html'); // create domdocument object, , load html string $dochtml = new domdocument(); $dochtml->loadhtml($strhtml); $elm = $dochtml->getelementbyid('uppanelactuciones'); $segatiel= $dochtml->savexml($elm); $order = array("á","é","Ã","ó","ú","ñ"); $replace = array("á","é","í","ó","ú","ñ"); $megin = str_replace($order, $replace,$segatiel); echo $megin;
but apparently str_replace function doesn't work because output preserver rare characters (like ó). there way create str_replace work?
thanks in advance help.
pd: have html charset utf-8 set.
update
try instead
$strhtml = file_get_contents('05001400300320100033100.html'); $dochtml = new domdocument(); $dochtml->loadhtml($strhtml); $elm = $dochtml->getelementbyid('uppanelactuciones'); $segatiel= $dochtml->savexml($elm); $trans = get_html_translation_table(html_entities); unset($trans["\""], $trans["<"], $trans[">"]); $megin = strtr($segatiel, $trans); echo $megin;
str_replace does't work international characters.
<?php /** * replace occurrences of search string replacement string. * * @author sean murphy <sean@iamseanmurphy.com> * @copyright copyright 2012 sean murphy. rights reserved. * @license http://creativecommons.org/publicdomain/zero/1.0/ * @link http://php.net/manual/function.str-replace.php * * @param mixed $search * @param mixed $replace * @param mixed $subject * @param int $count * @return mixed */ if (!function_exists('mb_str_replace')) { function mb_str_replace($search, $replace, $subject, &$count = 0) { if (!is_array($subject)) { // normalize $search , $replace both arrays of same length $searches = is_array($search) ? array_values($search) : array($search); $replacements = is_array($replace) ? array_values($replace) : array($replace); $replacements = array_pad($replacements, count($searches), ''); foreach ($searches $key => $search) { $parts = mb_split(preg_quote($search), $subject); $count += count($parts) - 1; $subject = implode($replacements[$key], $parts); } } else { // phone call mb_str_replace each subject in array, recursively foreach ($subject $key => $value) { $subject[$key] = mb_str_replace($search, $replace, $value, $count); } } homecoming $subject; } } ?>
but isn't htmlentities() whar looking for? http://www.php.net/manual/en/function.htmlentities.php
php dom replace
No comments:
Post a Comment