<?php
$offset = 0;
if ( isset($_POST['text']) && isset($_POST['searchfor']) && isset($_POST['replacewith']) ) {
$text = $_POST['text'];
$searchfor = $_POST['searchfor'];
$replacewith = $_POST['replacewith'];
$search_length = strlen($searchfor);
if (!empty($text) && !empty($searchfor) && !empty($replacewith)) {
while ($stringpos = strpos($text, $searchfor, $offset)) {
echo $stringpos.'<br/>';
echo $offset = $stringpos + $search_length.'<br/>';
}
}
else{
echo "There Mustn't be any Void Space in the Field.";
}
}
?>
<form action="index.php" method="POST">
<textarea name="text" placeholder="Enter the MSG here" rows="6" cols="30"></textarea><br/><br/>
<input type="text" name="searchfor" class="search" placeholder="Search for"><br/><br/>
<input type="text" name="replacewith" class="replace" placeholder="Replace with"><br/><br/>
<input type="submit" value="Find and Replace">
</form>
这就是每当我为搜索设置值时,我都会遇到错误的问题。
while ($stringpos = strpos($text, $searchfor, $offset))
注意:在第21行的C:''examplep''htdocs''Space''Find''index.php中遇到一个格式不正确的数值
任何人请在这里帮助我,任何帮助都将不胜感激。
$offset应该是数字的,但您在while本身中为其分配了一个字符串:
echo $offset = $stringpos + $search_length.'<br/>';
在这一行之后,$offset
不再是一个数字,第二次执行while时,您会得到
while($strpos=strpos($text,$search,(int)($offset))){
echo $offset=($strpos+$search_length)."<br>";
}
需要一个类型在循环中铸造。。。(int)($offset)
就是这样。