B
Ben Duffy
What perl functions should I use to be able to find a substring in a string,
& replace it with bold text, similar to Google search results highlighting?
for example
search "120gb Hard Disk Drive" for "disk" to result in "120gb Hard
<strong>Disk</strong> Drive"
The way I am currently doing this is...
$prodname = "120gb Hard Disk Drive" ;
$where_desc = "disk";
$prodname =~ s/$where_desc/<strong>$where_desc<\/strong>/gi;
which gives... "120gb Hard <strong>disk</strong> Drive"
The problem is that I want to retain the $prodname's original case.
I have tried using split, to get the string parts before & after the search
word, but can't assign the actual found word to a variable...
($before,$after)= split(/$where_desc/i,$proddesc);
only two variables are returned,
$before = "120gb Hard";
$after = "Drive";
but I can't assign "Disk" to a variable. If I could, then I could rejoin
after formatting.
Any help would be appeciated.
& replace it with bold text, similar to Google search results highlighting?
for example
search "120gb Hard Disk Drive" for "disk" to result in "120gb Hard
<strong>Disk</strong> Drive"
The way I am currently doing this is...
$prodname = "120gb Hard Disk Drive" ;
$where_desc = "disk";
$prodname =~ s/$where_desc/<strong>$where_desc<\/strong>/gi;
which gives... "120gb Hard <strong>disk</strong> Drive"
The problem is that I want to retain the $prodname's original case.
I have tried using split, to get the string parts before & after the search
word, but can't assign the actual found word to a variable...
($before,$after)= split(/$where_desc/i,$proddesc);
only two variables are returned,
$before = "120gb Hard";
$after = "Drive";
but I can't assign "Disk" to a variable. If I could, then I could rejoin
after formatting.
Any help would be appeciated.