Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.