•
•
•
•
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
![]() |
•
•
Join Date: Dec 2007
Posts: 52
Reputation:
Rep Power: 1
Solved Threads: 1
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.";
}•
•
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation:
Rep Power: 5
Solved Threads: 71
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+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
yes.. try:
php Syntax (Toggle Plain Text)
$search = $_GET['word'];
•
•
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation:
Rep Power: 5
Solved Threads: 71
It's a regular expression so the correction would be
php Syntax (Toggle Plain Text)
$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+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
•
•
Join Date: Apr 2005
Location: New York state
Posts: 468
Reputation:
Rep Power: 5
Solved Threads: 71
It works for all letters, you just can't use a variable inside single quotes.
php Syntax (Toggle Plain Text)
$myVar = 'Hello World'; $string = '/$myVar/'; //== /$myVar/ $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+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Problem with $_GET and JOIN (PHP)
- php relocation on $_Get (PHP)
- phpBB thread archive (PHP)
- BASIC FORM problems... (PHP)
- Help with a script (PHP)
- DLL not woking - Please help me (PHP)
- page.php?page=1,2,3,4,..inf. (PHP)
Other Threads in the PHP Forum
- Previous Thread: dynamic html
- Next Thread: multi column data display


Linear Mode