domDocument를 사용하여 html 태그를 찾습니다.domDocument 인코딩이 데이터베이스와 일치하지 않습니다.
$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가 내 데이터베이스에서 추출,이 필드는 utf8_general_ci이지만, 그것은 실패
array(3) {
[0]=> string(21) "Plaza de la Estación"
[1]=> string(10) "2013-04-22"
[2]=> string(8) "17:34:50" }
첫 번째 요소는 잘못된 인코딩이 있습니다.
어떻게 해결할 수 있습니까?
메타 태그를 추가하여 콘텐츠 유형을 설정하십시오. –