User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,378 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,042 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 524 | Replies: 5
Reply
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

$_GET

  #1  
Mar 22nd, 2008
can someone tell me whats wrong with my code?
$file= "/file.txt";
$search ='/$_GET[word]/i';
echo $search;
if (preg_match($search, $file))
{
echo "A match was found.";
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 71
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

  #2  
Mar 22nd, 2008
You are using single quotes (') for your $search string. Variables aren't parsed inside single quotes. So the search string right now is literally '/$_GET[word]/i'
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Nov 2007
Location: Indonesia
Posts: 15
Reputation: black_ip82 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
black_ip82's Avatar
black_ip82 black_ip82 is offline Offline
Newbie Poster

Re: $_GET

  #3  
Mar 22nd, 2008
yes.. try:
  1. $search = $_GET['word'];
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 71
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

  #4  
Mar 22nd, 2008
Originally Posted by black_ip82 View Post
yes.. try:
  1. $search = $_GET['word'];

It's a regular expression so the correction would be
  1. $search = "/$_GET[word]/i";
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: $_GET

  #5  
Mar 22nd, 2008
thx but how come it only works for some letters?
Last edited by kishou : Mar 22nd, 2008 at 12:06 pm.
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 71
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

  #6  
Mar 22nd, 2008
It works for all letters, you just can't use a variable inside single quotes.
  1. $myVar = 'Hello World';
  2. $string = '/$myVar/'; //== /$myVar/
  3. $string = "/$myVar/" //== /Hello World/
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC