我正在解析一个字符串,然后将其发送到数据库。我想查找该字符串中的所有
例如:
听起来很简单。我只需使用while循环,使用strpos获取所有
问题是我总是会得到一个错误,而且我不知道我做错了什么?可能是一个愚蠢的错误,但仍然很烦人。
以下是我的代码。
任何想法请?
先行感谢,
<br>
,并用来自数组的唯一数字替换它们,然后跟随一个新行。例如:
str = "Line <br> Line <br> Line <br> Line <br>"
$replace = array("1", "2", "3", "4");
my function would return
"Line 1 \n Line 2 \n Line 3 \n Line 4 \n"
听起来很简单。我只需使用while循环,使用strpos获取所有
<br>
的出现次数,并使用str_replace将其替换为所需的数字+\n。问题是我总是会得到一个错误,而且我不知道我做错了什么?可能是一个愚蠢的错误,但仍然很烦人。
以下是我的代码。
$str = "Line <br> Line <br> Line <br> Line <br>";
$replace = array("1", "2", "3", "4");
$replaceIndex = 0;
while(strpos($str, '<br>') != false )
{
$str = str_replace('<br>', $replace[index] . ' ' .'\n', $str); //str_replace, replaces the first occurance of <br> it finds
index++;
}
任何想法请?
先行感谢,
<br>
的实例... 要以这种方式完成,您只需使用substr_replace
替换字符串的部分,并定义替换的位置即可。 - prodigitalson