如何将php变量设置为xml中以下<STRONG>
标记内的所有内容:
<SAVED_EXPORT>
<metatag_description>
Some text here? The <strong> Cambro High-Impact 12" x 16" Dietary Tray</strong> is the solution. Comprised of high-impact, ligh
</metatag_description>
</SAVED_EXPORT>
<? foreach( $xml as $SAVED_EXPORT ) {
$header = $SAVED_EXPORT->metadescription;
echo $header[0];
}
?>
我希望它能吐出来: Cambro High-Impact 12“x 16”膳食托盘而非所有描述
答案 0 :(得分:0)
尝试添加以下表达式而不是echo:
if (preg_match("/\<\;strong\>\;(.*?)\<\;\/strong\>\;/si", $header[0], $match) == true)
{
echo $match[1];
}
答案 1 :(得分:0)
使用strpos和substr:
$string = 'Some text here? The <strong> Cambro High-Impact 12" x 16" Dietary Tray</strong> is the solution. Comprised of high-impact, ligh';
// Tag to look for
$tag = 'strong';
$start_tag = '<' . $tag . '>';
$end_tag = '</' . $tag . '>';
// Determine position of search pattern <strong>
$begin = strpos($string, $start_tag);
// Add the lenght of the tag string:
$begin += strlen($start_tag);
// Determine position of search pattern </strong>
$end = strpos($string, $end_tag);
// Calculate length:
$length = $end - $begin;
// echo the trimmed substring
echo trim(substr($string, $begin, $length));