Replace a string with a string that contains multiple & quot; # xxxxx # & quot; substrings. what should I do if I want to convert these substrings into other strings? # Xxxxx # Convert to & lt; imgsrc & quot; xxxxx & quot; & gt;, that is, extract the characters in # and replace # xxxxx # with & lt; characters obtained by imgsrc & gt; ------ solution ------ string replacement
There is a string with multiple substrings such as "# xxxxx #". what should I do if I want to convert these substrings into other strings?
# Xxxxx # is to extract the characters in # and replace # xxxxx #
------ Solution --------------------
Otherwise
$ Html = '# xxxxx ## xxxxx #';
$ Str = "# xxxxx #";
$ Str = str_replace ('# xxxxx #', '', $ html );
Echo $ str;
------ Solution --------------------
Discussion
Otherwise
$ Html = '# xxxxx ## xxxxx #';
$ Str = "# xxxxx #";
$ Str = str_replace ('# xxxxx #', '', $ html );
Echo $ str;
------ Solution --------------------
Discussion
Reference:
Otherwise
$ Html = '# xxxxx ## xxxxx #';
$ Str = "# xxxxx #";
$ Str = str_replace ('# xxxxx #', '', $ html );
Echo $ str;
What about regular expressions? Please advise
------ Solution --------------------
Echo preg_replace ('/# ([^ #] + ?) #/Is ', '', $ html );
------ Solution --------------------
Replace (the replaced string), the regular expression depends on what you are replacing and replacing. we recommend that you use replace
------ Solution --------------------
Modifier/u