problem with a function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fabby
Forum Commoner
Posts: 62
Joined: Tue Feb 15, 2005 1:06 am
Location: Romania
Contact:

problem with a function

Post 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();
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

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