简体   繁体   English

PHP strpos多个单词

[英]PHP strpos multiple words

Basically I'm trying to see if the following is in a variable called $restext . 基本上,我试图查看以下内容是否在名为$restext的变量中。

[TD="align: left"]'.$num.'[/TD] [TD="align: left"][/TD] [TD =“ align:left”]'。$ num。'[/ TD] [TD =“ align:left”] [/ TD]

$num is a $_GET value which is a number. $num是一个$_GET值,它是一个数字。

From what I see it is failing when I use: 从我看到的使用失败:

if(strpos($restext,'[TD="align: left"]'.$num.'[/TD] [TD="align: left"][/TD]')===false) {

}

because the string I am searching for is 2 words. 因为我要搜索的字符串是2个字。 There is a space after the first [/TD] 第一个[/TD]后有一个空格

How can I search the the variable $restext for the string posted above? 如何在变量$restext搜索上面发布的字符串?

Thanks! 谢谢!

Are you sure that you've taken into account the empty cell at the end? 您确定最后已经考虑了空单元格吗?

$haystack = 'pastebin example';
$num = 1;
$needle = '[TD="align: left"]'.$num.'[/TD] [TD="align: left"][/TD]';
echo strpos($haystack, $needle) === false ? "Not found" : "Found"; //Found
$num = 4;
echo strpos($haystack, $needle) === false ? "Not found" : "Found"; //Not found

If you want to replace the value: 如果要替换该值:

if(strpos($haystack, $needle) !== false) {
    $haystack = str_replace($needle, "New value", $haystack);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM