i have the function coloreaza_cuvant_gasitthat find and replace the word $cuvant with $cuvant_inlocuitor. But if in my page the word is writed with the first letter uppercase, then , str_replace function don't repalce the word. I have to use $rezultat=str_replace(ucfirst($cuvant_cautat),$cuvant_inlocuitor,$buffer); , but i don't know where to place it in the function...can u help me?
thanks
function coloreaza_cuvant_gasit($buffer){
global $cuvant_cautat;
global $cuvant_inlocuitor;
$rezultat=str_replace($cuvant_cautat,$cuvant_inlocuitor,$buffer);
return $rezultat;
}
ob_start("coloreaza_cuvant_gasit");
include("mypage.ro");
ob_end_flush();
problem with a function
Moderator: General Moderators
First of all, DON'T USE GLOBALS!!! Globals are the worst thing in programming.
Secodly, use when posting!
Thirdly...
And if you have PHP version below PHP5:
Secodly, use
Code: Select all
andThirdly...
Code: Select all
<?php
$rezultat=str_ireplace($cuvant_cautat, $cuvant_inlocuitor, $buffer); //Case-insensitive version of str_replace
ob_start("coloreaza_cuvant_gasit");
include("mypage.ro");
ob_end_flush();
?>Code: Select all
<?php
$rezultat=str_replace(strtolower($cuvant_cautat), strtolower($cuvant_inlocuitor), strtolower($buffer));
ob_start("coloreaza_cuvant_gasit");
include("mypage.ro");
ob_end_flush();
?>