我需要在value =“”的引号之间找到字符/字母,然后更改它。
我知道可以学习如何使用正则表达式等找到“未知数据”。
答案 0 :(得分:0)
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
$newstring = str_replace($parsed,"new phrase or whatever",$fullstring);
echo $newstring; // (result = this is my [tag]new phrase or whatever[/tag])