Page 1 of 1

problem with a function

Posted: Wed Jun 07, 2006 10:11 am
by fabby
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();

Posted: Wed Jun 07, 2006 10:40 am
by ok
First of all, DON'T USE GLOBALS!!! Globals are the worst thing in programming.

Secodly, use

Code: Select all

and
when posting!

Thirdly...

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();
?>
And if you have PHP version below PHP5:

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();
?>