Я использую регулярные выражения с помощью preg_replace () , чтобы найти и заменить предложение в части текста. $ Search_string содержит простой текст + теги HTML + & nbsp; элементы. Проблема в том, что только иногда элементы & nbsp; преобразуются в белое пространство во время выполнения, что затрудняет поиск и замену с помощью str_replace () . Итак, я пытаюсь создать шаблон, равный строке поиска и будет соответствовать чему -либо подобному, который содержит, или не содержит элементов & nbsp; < /code>; < /p>
Например: < /p>
$search_string = 'Two years in, the company has expanded to 35 cities, five of which are outside the U.S. Plus, in April, ClassPass acquired its main competitor, Fitmob.';
< /code>
$pattern = $ search_string (но игнорируйте элементы & nbsp; в субъекте)
$subject = "text text text text text". $search_string . "text text text text text";
< /code>
Using A regular expression to exclude a word/string, I've tried:
$pattern = '`^/(?!\ )'.$search_string.'`';
$output = preg_replace($pattern, $replacement_string,$subject);
< /code>
The end result will be that if the $subject does contains a string that is like my $seach_string, но без элементов & nbsp; он все равно будет соответствовать и заменить его на $ reatsive_string
edit:
Фактические значения:
$subject = file_get_contents("http://venturebeat.com/2015/11/10/sourc ... nd-others/");
$search_string = "Two years in, the company has expanded to 35 cities, five of which are outside the U.S. Plus, in April, ClassPass acquired its main competitor, Fitmob.";
$replacement_string = "Two years in, the company has expanded to 35 cities, five of which are outside the U.S. Plus, in April, ClassPass acquired its main competitor, Fitmob.";
Подробнее здесь: https://stackoverflow.com/questions/336 ... lar-string