Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-27-2009, 04:32 PM   #1
DigitalPimp
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Los Angeles, CA
Posts: 512
Need help with PHP code

Anyone know why the following does not return desired results and how to get it to?

Code:
$string = 'a,b,c,d';

if(eregi("(a)|(adf)|(c)",$string,$matchedtext)){ 
echo $matchedtext[1]; // This returns an "a" which I want
echo $matchedtext[2]; // This is empty, I want it to return a "c"
}
DigitalPimp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 04:40 PM   #2
DigitalPimp
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Los Angeles, CA
Posts: 512
Code should have read:

Code:
$string = 'a,b,c,d';

if(eregi("(a)|(c)|(adf)",$string,$matchedtext)){ 
echo $matchedtext[1]; // This returns an "a" which I want
echo $matchedtext[2]; // This is empty, I want it to return a "c"
}
DigitalPimp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 05:13 PM   #3
CS-Jay
Confirmed User
 
CS-Jay's Avatar
 
Join Date: Oct 2003
Location: Command Central, West Palm Beach, Fl
Posts: 1,794
who don't you do a print_r($matchedtext) to see what's in there?
__________________
I do stuff - aIm CS_Jay_D
CS-Jay is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 05:24 PM   #4
Beaver Bob
Confirmed User
 
Beaver Bob's Avatar
 
Join Date: Aug 2005
Location: Las Vegas, NV
Posts: 1,099
not sure exactly what you are trying to do here, but take some time to read up on regular expressions in PHP and you should be able to figure it out.

http://www.regular-expressions.info/php.html
http://www.php.net/manual/en/function.ereg.php
__________________
Spunky Dollars | Need Content?
Paysite Owners: Protect Your Members Area with Strongbox

361-574-229
Beaver Bob is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 05:30 PM   #5
DigitalPimp
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Los Angeles, CA
Posts: 512
Quote:
Originally Posted by CS-Jay View Post
who don't you do a print_r($matchedtext) to see what's in there?
print_r($matchedtext) returns:

Array ( [0] => a [1] => a [2] => [3] => )

My understanding is matchedtext[0] is supposed to return the complete string matched, matchedtext[1] is supposed to return the substring which starts at the first left parenthesis, matchedtext[2] the next and so on. For some reason matchedtext[2] is not returning the letter "c" as I would expect.
DigitalPimp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 05:35 PM   #6
DigitalPimp
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Los Angeles, CA
Posts: 512
Quote:
Originally Posted by Beaver Bob View Post
not sure exactly what you are trying to do here, but take some time to read up on regular expressions in PHP and you should be able to figure it out.

http://www.regular-expressions.info/php.html
http://www.php.net/manual/en/function.ereg.php
I am trying to get the second substring "(c)" to get stored in the $matchedtext array. I will review those pages.
DigitalPimp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 06:39 PM   #7
calmlikeabomb
Confirmed User
 
calmlikeabomb's Avatar
 
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
You owe me a blow job.

It could be shorter, but that takes time, more thought and money.

PHP Code:
<?php

$string 
'a,b,c,d';

foreach(
explode(','$string) as $match) {
    if(
in_array($match, array('a','c'))) $matches[] = $match;
}

print_r($matches); // Here are your items.

?>
__________________
subarus.

Last edited by calmlikeabomb; 05-27-2009 at 06:41 PM..
calmlikeabomb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-27-2009, 07:07 PM   #8
DigitalPimp
Confirmed User
 
Industry Role:
Join Date: Jun 2003
Location: Los Angeles, CA
Posts: 512
thank you!
DigitalPimp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.