by

PHP basic function to find a word in a string

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4313798/PHP-basic-function-to-find-a-word-in-a-s?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?php function replaceText($text) { // The wanted word $expected = "World"; $save = str_replace($expected, "<b>World</b>", $text); $cont = strpos($text, $expected) !== false; if($cont == true){ echo "True: " . $save; } else { echo "False: " . $text; } } // the call function replaceText("Hello World");
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus