Regarding how str_replace_once only replaces the content but not the alt tag in

WBOY
Release: 2016-09-09 08:27:57
Original
2455 people have browsed it

About str_replace_once($needle,$replace,$haystack), how to replace only the content without replacing the alt and title tags in

The original code is as follows
Code 1:

<code>public function str_replace_once($needle,$replace,$haystack) 
{
    $pos = strpos($haystack, $needle);
 
    if ($pos === false) 
    {
        return $haystack;
    }
     
    return substr_replace($haystack, $replace, $pos, strlen($needle));
}
</code>
Copy after login
Copy after login

Please help me how can I replace only the text content when replacing characters, but not the alt and title characters in the image

My purpose is, there is an article $str, and then there is an array $arr=array("小草","小花","狗","Willow"); I want to include all the array contents in the article. Replace it with something like Xiaocaohuahua, which is equivalent to an internal link in the article, but when encountering
Xiaocao//does not operate
aaa//does not operate

aa

//Do not operate
...
Although there are contents containing arrays, they are not replaced.

Reply content:

About str_replace_once($needle,$replace,$haystack), how to replace only the content without replacing the alt and title tags in

The original code is as follows
Code 1:

<code>public function str_replace_once($needle,$replace,$haystack) 
{
    $pos = strpos($haystack, $needle);
 
    if ($pos === false) 
    {
        return $haystack;
    }
     
    return substr_replace($haystack, $replace, $pos, strlen($needle));
}
</code>
Copy after login
Copy after login

Please help me how can I replace only the text content when replacing characters, but not the alt and title characters in the image

My purpose is, there is an article $str, and then there is an array $arr=array("小草","小花","狗","Willow"); I want to include all the array contents in the article. Replace it with something like Xiaocaohuahua, which is equivalent to an internal link in the article, but when encountering
Xiaocao//does not operate
aaa//does not operate

aa

//Do not operate
...
Although there are contents containing arrays, they are not replaced.

String replacement is no longer enough for you, please try regular expressions.

Or if you want to process tags, you can try those plug-ins for xml parsing

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!