<?php
$offset =0;
if (isset ($_POST['text']) && isset($_POST['searchfor'])&&isset($_POST['replacewith']))
{
$text = $_POST['text'];
$search = $_POST['searchfor'];
$replace = $_POST['replacewith'];
$length = strlen($search);
if (!empty($_POST['text'])&& !empty($_POST['searchfor'])&&!empty($_POST['replacewith']))
{
while ($stringpos = strpos($text, $search, $offset))
{
$offset = $stringpos + $length;
$text = substr_replace($text, $replace, $stringpos, $length);
}
echo $text;
}
else
{
echo 'Please fill in all the fields';
}
}
?>
<form action=53fineandreplace.php method="POST">
<textarea name = "text" rows="6" cols = "30"></textarea><br><br>
Search For:<br>
<input type= "text" name = "searchfor"><br><br>
Replace with:<br>
<input type="text" name = "replacewith"><br><br>
<input type = "submit" value = "Submit">
</form>
Si le mot à remplacer est le premier mot ou le seul mot dans la chaîne alors cela ne fonctionne pas mais si le mot à remplacer est dans toute autre position sauf la première alors ça marche bien.pourquoi ce php substr_replace() ne remplace pas le premier mot