第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

strstr 不適用于 xml 文件中的變量

strstr 不適用于 xml 文件中的變量

PHP
慕田峪9158850 2022-01-02 16:21:11
我對(duì) php 中的函數(shù) strstr 有一些問題。 $text=file_get_contents("text.txt");  echo $text.'<br><br>'; $xml = simplexml_load_file('listmv.xml'); foreach($xml->item as $item) {$quoi="sangs rgyas";if (strstr($text,$quoi)) { echo 'yes';} }strstr 返回“是”, $text=file_get_contents("text.txt"); echo $text.'<br><br>'; $xml = simplexml_load_file('listmv.xml'); foreach($xml->item as $item) {$quoi=$item->tib;if (strstr($text,$quoi)) { echo 'yes';} }不起作用。這是怎么回事?XML 文件:-<list>   <item>    <tib>sangs rgyas</tib>    <ref>1524</ref>  </item>   <item>    <tib>rgya gar skad du</tib>    <ref>1522</ref>  </item>   <item>    <tib>shes pa dang</tib>    <ref>1523</ref>  </item>   <item>    <tib>'tsho ba dang</tib>    <ref>1525</ref>  </item> </list> 
查看完整描述

2 回答

?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

當(dāng)您在循環(huán)中從 SimpleXML 返回一個(gè)項(xiàng)目時(shí)...


foreach($xml->item as $item)

{

    $quoi=$item->tib;

    if (strstr($text,$quoi)) { echo 'yes';}

}

如果你添加


var_dump($quoi);

你會(huì)看到它實(shí)際上是一個(gè) SimpleXMLElement 而不是一個(gè)字符串......


class SimpleXMLElement#5 (1) {

  public ${0} =>

  string(11) "sangs rgyas"

}

之類的東西echo會(huì)將其轉(zhuǎn)換為字符串,因此請(qǐng)使用


if (strstr($text,(string)$quoi)) { echo 'yes';}


查看完整回答
反對(duì) 回復(fù) 2022-01-02
?
子衿沉夜

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

它正在返回一個(gè)您需要將其轉(zhuǎn)換為字符串的對(duì)象。更正的代碼


 $text=file_get_contents("text.txt");

 echo $text.'<br><br>';

 $xml = simplexml_load_file('listmv.xml');

 foreach($xml->item as $item)

 {

$quoi=$item->tib;

if (strstr($text,$quoi->__toString())) { echo 'yes';}

 }


查看完整回答
反對(duì) 回復(fù) 2022-01-02
  • 2 回答
  • 0 關(guān)注
  • 158 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)