$_GET

Reply

Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

$_GET

 
0
  #1
Mar 22nd, 2008
can someone tell me whats wrong with my code?
  1. $file= "/file.txt";
  2. $search ='/$_GET[word]/i';
  3. echo $search;
  4. if (preg_match($search, $file))
  5. {
  6. echo "A match was found.";
  7. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,431
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 233
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: black_ip82 is an unknown quantity at this point 
Solved Threads: 0
black_ip82's Avatar
black_ip82 black_ip82 is offline Offline
Newbie Poster

Re: $_GET

 
0
  #3
Mar 22nd, 2008
yes.. try:
  1. $search = $_GET['word'];
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,431
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 233
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: $_GET

 
0
  #5
Mar 22nd, 2008
thx but how come it only works for some letters?
Last edited by kishou; Mar 22nd, 2008 at 1:06 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,431
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 233
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: $_GET

 
0
  #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 y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1057 | Replies: 5
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC