473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHP regex help

I'm new to PHP regex. What I am trying to match is:

http://library.dayton.town.net

it's a mysql/php field.

Then if a match I take some action.

But it's not working any help appreciated. Thanks
while ( $row = mysql_fetch_row( $result ) ) {...
.....
foreach($row as $data) {
if ( preg_match ( "/http://library\.dayton\.town\.net/", $data ) )
$data= 'You got a match';

.....
Jul 17 '05 #1
5 1666

"leegold2" <le******@verizon.net> wrote in message
news:wz******************@nwrddc01.gnilink.net...
I'm new to PHP regex. What I am trying to match is:

http://library.dayton.town.net

it's a mysql/php field.

Then if a match I take some action.

But it's not working any help appreciated. Thanks
while ( $row = mysql_fetch_row( $result ) ) {...
....
foreach($row as $data) {
if ( preg_match ( "/http://library\.dayton\.town\.net/", $data ) )
$data= 'You got a match';

....


Without looking too closely or trying it, the // after http: are likely
being translated as pattern terminators. Escape them ("leaning toothpick"
syndrome ahoy), or change the terminators from / to something else like ?.
Escape anything that isn't alphanumeric for safety, too (the : character).
$pattern="?http\://library\.dayton\.town\.net?";
or
$pattern="/http\:\/\/library\.dayton\.town\.net/";
Then
if ( preg_match ( $pattern, $data ) )
Etc.

Of course, in this case you could always use
if($data == "http://library.dayton.town.net")
........

lol

Garp
Jul 17 '05 #2
Garp wrote:
"leegold2" <le******@verizon.net> wrote in message
news:wz******************@nwrddc01.gnilink.net...
I’m new to PHP regex. What I am trying to match is:

http://library.dayton.town.net

it’s a mysql/php field.

Then if a match I take some action.

But it’s not working any help appreciated. Thanks
while ( $row = mysql_fetch_row( $result ) ) {...
....
foreach($row as $data) {
if ( preg_match ( "/http://library\.dayton\.town\.net/", $data ) )
$data= ’You got a match’;

....
Without looking too closely or trying it, the // after http: are likely
being translated as pattern terminators. Escape them ("leaning

toothpick" syndrome ahoy), or change the terminators from / to something else like ?. Escape anything that isn’t alphanumeric for safety, too (the : character). $pattern="?http\://library\.dayton\.town\.net?";
or
$pattern="/http\:\/\/library\.dayton\.town\.net/";
Then
if ( preg_match ( $pattern, $data ) )
Etc.

Of course, in this case you could always use
if($data == "http://library.dayton.town.net")
........

lol

Garp

or so a simple substring match:

if (strstr($data, "http://library.dayton.town.net")) { ....

http://ca3.php.net/manual/en/function.strstr.php

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-regex-he...ict125133.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=416874
Jul 17 '05 #3

"steve" <Us************@dbForumz.com> wrote in message
news:22******************************@news.teranew s.com...
Garp wrote:
> "leegold2" <le******@verizon.net> wrote in message
> news:wz******************@nwrddc01.gnilink.net...
> > I'm new to PHP regex. What I am trying to match is:
> >
> > http://library.dayton.town.net
> >
> > it's a mysql/php field.
> >
> > Then if a match I take some action.
> >
> > But it's not working any help appreciated. Thanks
> >
> >
> > while ( $row = mysql_fetch_row( $result ) ) {...
> > ....
> > foreach($row as $data) {
> > if ( preg_match ( "/http://library\.dayton\.town\.net/", $data ) ) > > $data= 'You got a match';
> >
> > ....

>
> Without looking too closely or trying it, the // after http: are likely
> being translated as pattern terminators. Escape them ("leaning

toothpick"
> syndrome ahoy), or change the terminators from / to something else

like ?.
> Escape anything that isn't alphanumeric for safety, too (the :

character).
> $pattern="?http\://library\.dayton\.town\.net?";
> or
> $pattern="/http\:\/\/library\.dayton\.town\.net/";
> Then
> if ( preg_match ( $pattern, $data ) )
> Etc.
>
> Of course, in this case you could always use
> if($data == "http://library.dayton.town.net")
> ........
>
> lol
>
> Garp

or so a simple substring match:

if (strstr($data, "http://library.dayton.town.net")) { ....

http://ca3.php.net/manual/en/function.strstr.php

--


This is turning into a JAPH thread. 8D (I tried my techniques for the OP
today, they're both good).

Garp
Jul 17 '05 #4
leegold2 wrote:
I'm new to PHP regex. What I am trying to match is:

http://library.dayton.town.net


Dude,

This isn't exactly your script, but paste this into a new .php file,
upload it to your server, run it in a browser, and tell me if it echos
"You got a match":

/*BEGIN SCRIPT*/
<?

$data = htmlspecialchars("http://library.dayton.town.net");
if ( preg_match ( '[http://library\.dayton\.town\.net]', $data ) ) {
echo "You got a match";
} else {
echo "You did not get a match";
}
?>
/*END SCRIPT*/

--
'bonehead

Jul 17 '05 #5
Thanks for all the help - I paid extra special
attention to escaping the special chars and
got it too work.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.