Current location: Hot Scripts Forums » Programming Languages » PHP » str_replace or ... ?, insensitive string replace Options


str_replace or ... ?, insensitive string replace Options

Reply
  #1 (permalink)  
Old 03-07-06, 06:29 PM
ibzi ibzi is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
str_replace or ... ?, insensitive string replace Options

Let's say I have a paragraph of text.


"This forum is phpfreaks.com and the person posting this message goes by the Username of ibzi. This is just a paragraph to show an example to the fellow helpers."

Now lets say I want to replace all the occurence of the word "and" regardless about the case. It can be And or AND or aND etc.

How would i do this? I want to replace it with something like:

and >>>>>> <a target="_blank" href="search.php?q=and">and</a>

I tried preg_match but I dont know how to use the function, i constantly get wrong result near the "_blank".

Please help.. it will be appreciated.
__________________
--
Help us Fight SPAM!
Reply With Quote
  #2 (permalink)  
Old 03-07-06, 07:05 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Something like this -
PHP Code:

<?php

$source 
"This forum is phpfreaks.com and the person posting this message goes by the Username of ibzi And AND anD aNd ANd aND AnD. This is just a paragraph to show an example to the fellow helpers.";

$searchfor "and";

$replacewith "<a target='_blank' href='search.php?q=$searchfor'>$searchfor</a>";

$replaced str_ireplace($searchfor$replacewith$source);

echo 
"$source<br><br>";
echo 
"$replaced<br>";
?>
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 03-07-06, 07:28 PM
ibzi ibzi is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply however I dont have the str_ireplace function. I've got a older PHP version is installed.
__________________
--
Help us Fight SPAM!
Reply With Quote
  #4 (permalink)  
Old 03-07-06, 08:04 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
This works as well -
PHP Code:

$replaced eregi_replace($searchfor$replacewith$source); 

PHP3, 4, 5
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wanted to replace special characters in MS Access using VB, but more than 1 character cebuy Visual Basic 3 12-04-05 05:30 PM
how to search and replace patten in string robbydweb PHP 1 11-17-05 12:11 PM
replace pattern-problm with pointers Erev0s C/C++ 0 05-25-04 02:30 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.