TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-22-2008, 01:41 PM   #1 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default str_replace??

I have this code

PHP Code:
$highlightWords explode(" "$searchString);
$s sizeof($highlightWords);
for(
$i=0;$i<=$s;$i++) {
$info str_replace($highlightWords[i], "<span class=\"highlight\">$highlightWords[i]</span>"$info);

And it does not work. However If i just do
PHP Code:
$info str_replace($highlightWords[0], "<span class=\"highlight\">$highlightWords[0]</span>"$info); 
without the loop it seems to work.

My array contains a couple words that were entered into the search bar.

What i am doing with this code is searching a string and highlighting everywhere that a searched word appears.

any ideas?
CoryMathews is offline  
Reply With Quote
Old 09-22-2008, 02:00 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You have a typing mistake, $highlightWords[i] should be $highlightWords[$i]

It is advisable to turn on full error reporting when writing code to catch simple little problems like this, using error_reporting(E_ALL)
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
CoryMathews (09-22-2008)
Old 09-22-2008, 02:04 PM   #3 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

ah sob. It probably would of taken me another hour to see that. Time for a break. Thanks salathe.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 04:52 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design