Jump to content

preg_replace - I don't want it to be case sensitive


surfwtw

Recommended Posts

I am using preg_replace to automatically bold "$word" when it appears. It will only replace the word when capitalized. How can I get it to replace the word without being case sensitive.

 

Also could I also throw a link in? I tried and I get a syntax error. I'm guessing the links in PHP are different than HTML

 

Here is my code

 

 

<?php

 

$find ="/$word/";

$replace ="<b>$word</b>";

 

Echo preg_replace ($find, $replace, $definition); ?>

 

Thanks

Do you mean converting the text that you find into a link? You already have the right idea with your idea converting it into bold, except you would just do

 

<?php

$find ="/$word/i";
$replace ="<a href='page.php'>$word</a>";

Echo preg_replace ($find, $replace, $definition); ?>

 

or do go a bit further, perhaps you want the text to be converted into a clickable link that goes to a page that searches for that term?

 

<?php

$find ="/$word/i";
$replace ="<a href='search.php?search=$word'>$word</a>";

Echo preg_replace ($find, $replace, $definition); ?>

 

is that what you meant?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.