Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread Jochem Maas
Nitsan Bin-Nun schreef:
 Hi lista,
 
 I have been trying to figure this out for the last couple of hours but I'm
 lack of luck.
 Take a look at these regex's, the string that was inputed into the
 preg_replace (using Uis modificators) and the results:
 (the lists have correspondence to each other)
 
 ORIGINAL STRING
 
 
 http://www.zshare.net/video/541070871c7a8d9c
 http://www.guba.com/watch/2000821351
 http://www.veoh.com/videos/v4609719YfsCFpf
 
 
 REGEX USED (with Uis modificators)
 
 http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
 http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
 http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
 THE RETURNED STRING
 
 41070871c7a8d9c
 000821351
 4609719YfsCFpf
 
 If you will go through this carefully you will notice that the first
 character of each matching group is being deleted.
 The regex's and the replacements string are being fetched from the database
 (mysql) and goes straight to the preg_replace function with the original
 string.
 
 I have no idea why this happens.
 I'm looking forward for your opinions and suggestions.

php -r '
var_dump(preg_replace(#http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)#Ui, 
\\2, http://www.zshare.net/video/541070871c7a8d9c;));
'
string(16) 541070871c7a8d9c

given the above test I don't see the problem with the regexp
(but you don't actually show the code so it's hard to tell), I'd
probably look else where for the char munching culprit.

 
 Regards,
 Nitsan
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread 9el
On Sat, Mar 7, 2009 at 2:37 PM, Jochem Maas joc...@iamjochem.com wrote:

 Nitsan Bin-Nun schreef:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.

 php -r '
 var_dump(preg_replace(#http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)#Ui,
 \\2, http://www.zshare.net/video/541070871c7a8d9c;));
 '
 string(16) 541070871c7a8d9c

 given the above test I don't see the problem with the regexp
 (but you don't actually show the code so it's hard to tell), I'd
 probably look else where for the char munching culprit.


Well, yes if Nitsun is not sharing his piece of code we will have to guess
wildly... but why? :)



 
  Regards,
  Nitsan
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread Nitsan Bin-Nun
There is no reason to share the code because it happens with almost ALL the
regex's I'm using :(

But I worked this out using Todd's solution.

Thank you all for trying to help.

On Sat, Mar 7, 2009 at 11:06 AM, 9el le...@phpxperts.net wrote:


 On Sat, Mar 7, 2009 at 2:37 PM, Jochem Maas joc...@iamjochem.com wrote:

 Nitsan Bin-Nun schreef:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.

 php -r '
 var_dump(preg_replace(#http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)#Ui,
 \\2, http://www.zshare.net/video/541070871c7a8d9c;));
 '
 string(16) 541070871c7a8d9c

 given the above test I don't see the problem with the regexp
 (but you don't actually show the code so it's hard to tell), I'd
 probably look else where for the char munching culprit.


 Well, yes if Nitsun is not sharing his piece of code we will have to guess
 wildly... but why? :)



 
  Regards,
  Nitsan
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread 9el
---
Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
a Free CD of Ubuntu mailed to your door without any cost. Visit :
www.ubuntu.com
--


On Sat, Mar 7, 2009 at 3:46 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:

 There is no reason to share the code because it happens with almost ALL the
 regex's I'm using :(

 But I worked this out using Todd's solution.

 Thank you all for trying to help.


hahaha   FUNNIEST ever . well we can conclude that you were wrong with
your codes of regex. :D



 On Sat, Mar 7, 2009 at 11:06 AM, 9el le...@phpxperts.net wrote:


 On Sat, Mar 7, 2009 at 2:37 PM, Jochem Maas joc...@iamjochem.com wrote:

 Nitsan Bin-Nun schreef:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the
 original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.

 php -r '
 var_dump(preg_replace(#http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)#Ui,
 \\2, http://www.zshare.net/video/541070871c7a8d9c;));
 '
 string(16) 541070871c7a8d9c

 given the above test I don't see the problem with the regexp
 (but you don't actually show the code so it's hard to tell), I'd
 probably look else where for the char munching culprit.


 Well, yes if Nitsun is not sharing his piece of code we will have to guess
 wildly... but why? :)



 
  Regards,
  Nitsan
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php






Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread Nitsan Bin-Nun
Yes you can ;)

and I'm using ubuntu :P

On Sat, Mar 7, 2009 at 12:08 PM, 9el le...@phpxperts.net wrote:


 ---
 Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
 a Free CD of Ubuntu mailed to your door without any cost. Visit :
 www.ubuntu.com
 --


 On Sat, Mar 7, 2009 at 3:46 PM, Nitsan Bin-Nun nit...@binnun.co.ilwrote:

 There is no reason to share the code because it happens with almost ALL
 the regex's I'm using :(

 But I worked this out using Todd's solution.

 Thank you all for trying to help.


 hahaha   FUNNIEST ever . well we can conclude that you were wrong with
 your codes of regex. :D



 On Sat, Mar 7, 2009 at 11:06 AM, 9el le...@phpxperts.net wrote:


 On Sat, Mar 7, 2009 at 2:37 PM, Jochem Maas joc...@iamjochem.comwrote:

 Nitsan Bin-Nun schreef:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the
 original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.

 php -r '
 var_dump(preg_replace(#http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)#Ui,
 \\2, http://www.zshare.net/video/541070871c7a8d9c;));
 '
 string(16) 541070871c7a8d9c

 given the above test I don't see the problem with the regexp
 (but you don't actually show the code so it's hard to tell), I'd
 probably look else where for the char munching culprit.


 Well, yes if Nitsun is not sharing his piece of code we will have to
 guess wildly... but why? :)



 
  Regards,
  Nitsan
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php







Re: [PHP] Unexplained Issue Using Regex

2009-03-07 Thread 9el
On Sat, Mar 7, 2009 at 4:10 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:

 Yes you can ;)

 and I'm using ubuntu :P


There's a fun joke in My Mothertongue Bangla (5th most spoken in the world
by about 300million).

Anis dis na   =  Take but never giveaway

Anis is a common arabic name but in Bangla  Anis means   'you may/can
bring/take in'
dis = to give
na = no

:D




 On Sat, Mar 7, 2009 at 12:08 PM, 9el le...@phpxperts.net wrote:


 ---
 Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
 a Free CD of Ubuntu mailed to your door without any cost. Visit :
 www.ubuntu.com
 --


 On Sat, Mar 7, 2009 at 3:46 PM, Nitsan Bin-Nun nit...@binnun.co.ilwrote:

 There is no reason to share the code because it happens with almost ALL
 the regex's I'm using :(

 But I worked this out using Todd's solution.

 Thank you all for trying to help.


 hahaha   FUNNIEST ever . well we can conclude that you were wrong with
 your codes of regex. :D







[PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Hi lista,

I have been trying to figure this out for the last couple of hours but I'm
lack of luck.
Take a look at these regex's, the string that was inputed into the
preg_replace (using Uis modificators) and the results:
(the lists have correspondence to each other)

ORIGINAL STRING


http://www.zshare.net/video/541070871c7a8d9c
http://www.guba.com/watch/2000821351
http://www.veoh.com/videos/v4609719YfsCFpf


REGEX USED (with Uis modificators)

http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)

THE RETURNED STRING

41070871c7a8d9c
000821351
4609719YfsCFpf

If you will go through this carefully you will notice that the first
character of each matching group is being deleted.
The regex's and the replacements string are being fetched from the database
(mysql) and goes straight to the preg_replace function with the original
string.

I have no idea why this happens.
I'm looking forward for your opinions and suggestions.

Regards,
Nitsan


Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Adam
would this not work? :

?php

$string = http://www.zshare.net/video/541070871c7a8d9c;;
$replaceWithThis = 'HELLYES-';

echo $string.\n;
echo preg_replace('/\S+video\//',$replaceWithThis,$string).\n;
echo $replaceWithThis.substr($string, strripos($string, '/')+1,
strlen($string)).\n;
echo $replaceWithThis.substr(strrchr($string, '/'), 1,
strlen(strrchr($string, '/')));


?

OUTPUT:

C:\php test.php
http://www.zshare.net/video/541070871c7a8d9c
HELLYES-541070871c7a8d9c
HELLYES-541070871c7a8d9c
HELLYES-541070871c7a8d9c
C:\

On Fri, Mar 6, 2009 at 2:32 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:
 Hi lista,

 I have been trying to figure this out for the last couple of hours but I'm
 lack of luck.
 Take a look at these regex's, the string that was inputed into the
 preg_replace (using Uis modificators) and the results:
 (the lists have correspondence to each other)

 ORIGINAL STRING
 

 http://www.zshare.net/video/541070871c7a8d9c
 http://www.guba.com/watch/2000821351
 http://www.veoh.com/videos/v4609719YfsCFpf


 REGEX USED (with Uis modificators)
 
 http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)               $3
 http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)              $3
 http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)

 THE RETURNED STRING
 
 41070871c7a8d9c
 000821351
 4609719YfsCFpf

 If you will go through this carefully you will notice that the first
 character of each matching group is being deleted.
 The regex's and the replacements string are being fetched from the database
 (mysql) and goes straight to the preg_replace function with the original
 string.

 I have no idea why this happens.
 I'm looking forward for your opinions and suggestions.

 Regards,
 Nitsan




-- 
Adi...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Haven't tested your code but from a rapid look it would work.

The issue here is that I don't understand why my expression doesn't catches
the full match and emits the first character?

On Fri, Mar 6, 2009 at 10:17 PM, Adam adiszak...@gmail.com wrote:

 would this not work? :

 ?php

 $string = http://www.zshare.net/video/541070871c7a8d9c;;
 $replaceWithThis = 'HELLYES-';

 echo $string.\n;
 echo preg_replace('/\S+video\//',$replaceWithThis,$string).\n;
 echo $replaceWithThis.substr($string, strripos($string, '/')+1,
 strlen($string)).\n;
 echo $replaceWithThis.substr(strrchr($string, '/'), 1,
 strlen(strrchr($string, '/')));


 ?

 OUTPUT:

 C:\php test.php
 http://www.zshare.net/video/541070871c7a8d9c
 HELLYES-541070871c7a8d9c
 HELLYES-541070871c7a8d9c
 HELLYES-541070871c7a8d9c
 C:\

 On Fri, Mar 6, 2009 at 2:32 PM, Nitsan Bin-Nun nit...@binnun.co.il
 wrote:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.
 
  Regards,
  Nitsan
 



 --
 Adi...



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Jim Lucas
Nitsan Bin-Nun wrote:
 Hi lista,
 
 I have been trying to figure this out for the last couple of hours but I'm
 lack of luck.
 Take a look at these regex's, the string that was inputed into the
 preg_replace (using Uis modificators) and the results:
 (the lists have correspondence to each other)
 
 ORIGINAL STRING
 
 
 http://www.zshare.net/video/541070871c7a8d9c
 http://www.guba.com/watch/2000821351
 http://www.veoh.com/videos/v4609719YfsCFpf
 
 
 REGEX USED (with Uis modificators)
 
 http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
 http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
 http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
 THE RETURNED STRING
 
 41070871c7a8d9c
 000821351
 4609719YfsCFpf
 
 If you will go through this carefully you will notice that the first
 character of each matching group is being deleted.
 The regex's and the replacements string are being fetched from the database
 (mysql) and goes straight to the preg_replace function with the original
 string.
 
 I have no idea why this happens.
 I'm looking forward for your opinions and suggestions.
 
 Regards,
 Nitsan
 

In my opinion...

http://us3.php.net/parse_url   is your friend here...

?php

$urls[] = 'http://www.zshare.net/video/541070871c7a8d9c';
$urls[] = 'http://www.guba.com/watch/2000821351';
$urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';

$url_paths = array();

foreach ( $urls AS $id = $url ) {
$url_paths[$id] = parse_url($url, PHP_URL_PATH);
}

print_r($url_paths);

foreach ( $url_paths AS $paths ) {
list( , ,$value) = explode('/', $paths, 3);
echo $value;
}

?

The above outputs the following:



-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Jim Lucas
Jim Lucas wrote:
 Nitsan Bin-Nun wrote:
 Hi lista,

 I have been trying to figure this out for the last couple of hours but I'm
 lack of luck.
 Take a look at these regex's, the string that was inputed into the
 preg_replace (using Uis modificators) and the results:
 (the lists have correspondence to each other)

 ORIGINAL STRING
 

 http://www.zshare.net/video/541070871c7a8d9c
 http://www.guba.com/watch/2000821351
 http://www.veoh.com/videos/v4609719YfsCFpf


 REGEX USED (with Uis modificators)
 
 http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
 http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
 http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)

 THE RETURNED STRING
 
 41070871c7a8d9c
 000821351
 4609719YfsCFpf

 If you will go through this carefully you will notice that the first
 character of each matching group is being deleted.
 The regex's and the replacements string are being fetched from the database
 (mysql) and goes straight to the preg_replace function with the original
 string.

 I have no idea why this happens.
 I'm looking forward for your opinions and suggestions.

 Regards,
 Nitsan

 
 In my opinion...
 
 http://us3.php.net/parse_url   is your friend here...
 
 ?php
 
 $urls[] = 'http://www.zshare.net/video/541070871c7a8d9c';
 $urls[] = 'http://www.guba.com/watch/2000821351';
 $urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';
 
 $url_paths = array();
 
 foreach ( $urls AS $id = $url ) {
   $url_paths[$id] = parse_url($url, PHP_URL_PATH);
 }
 
 print_r($url_paths);
 
 foreach ( $url_paths AS $paths ) {
   list( , ,$value) = explode('/', $paths, 3);
   echo $value.PHP_EOL;
 }
 
 ?
 
 The above outputs the following:
 
CTRL - Enter a little quick...

plaintextArray
(
[0] = /video/541070871c7a8d9c
[1] = /watch/2000821351
[2] = /videos/v4609719YfsCFpf
)
541070871c7a8d9c
2000821351
v4609719YfsCFpf

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
I'm not looking for other ideas, the main thing here is that I have about
30-100 regex's in the database and the script fetches them and applies them
to the string. I can't build again the engine and I'm not going to do that.
I'm trying to solve my problem ;) If you have any ideas regarding my issue
and not going in another way this would be very appreciated.

Thank you again for trying to help.

On Fri, Mar 6, 2009 at 11:40 PM, Jim Lucas li...@cmsws.com wrote:

 Nitsan Bin-Nun wrote:
  Hi lista,
 
  I have been trying to figure this out for the last couple of hours but
 I'm
  lack of luck.
  Take a look at these regex's, the string that was inputed into the
  preg_replace (using Uis modificators) and the results:
  (the lists have correspondence to each other)
 
  ORIGINAL STRING
  
 
  http://www.zshare.net/video/541070871c7a8d9c
  http://www.guba.com/watch/2000821351
  http://www.veoh.com/videos/v4609719YfsCFpf
 
 
  REGEX USED (with Uis modificators)
  
  http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
  http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
  http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
 
  THE RETURNED STRING
  
  41070871c7a8d9c
  000821351
  4609719YfsCFpf
 
  If you will go through this carefully you will notice that the first
  character of each matching group is being deleted.
  The regex's and the replacements string are being fetched from the
 database
  (mysql) and goes straight to the preg_replace function with the original
  string.
 
  I have no idea why this happens.
  I'm looking forward for your opinions and suggestions.
 
  Regards,
  Nitsan
 

 In my opinion...

 http://us3.php.net/parse_url   is your friend here...

 ?php

 $urls[] = 'http://www.zshare.net/video/541070871c7a8d9c';
 $urls[] = 'http://www.guba.com/watch/2000821351';
 $urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';

 $url_paths = array();

 foreach ( $urls AS $id = $url ) {
$url_paths[$id] = parse_url($url, PHP_URL_PATH);
 }

 print_r($url_paths);

 foreach ( $url_paths AS $paths ) {
list( , ,$value) = explode('/', $paths, 3);
echo $value;
 }

 ?

 The above outputs the following:



 --
 Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
by William Shakespeare



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:
 I'm not looking for other ideas, the main thing here is that I have about
 30-100 regex's in the database and the script fetches them and applies them
 to the string. I can't build again the engine and I'm not going to do that.
 I'm trying to solve my problem ;) If you have any ideas regarding my issue
 and not going in another way this would be very appreciated.

Nitsan,

I think it's because you're referencing the capture group with index
instead of index 2. Also, I don't understand why you have the pipe
(|) character in your regex string... is that part of your engine?

This code:

$orig = 'http://www.zshare.net/video/541070871c7a8d9c';
$matches = array();
preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
echo $matches[2];

Grabs the correct match:

541070871c7a8d9c

The regex pattern works with the pipe char, but it is unnecessary and
may lead to some strange behavior.

Hope this helps,


--
// Todd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:53 PM, haliphax halip...@gmail.com wrote:
 On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:
 I'm not looking for other ideas, the main thing here is that I have about
 30-100 regex's in the database and the script fetches them and applies them
 to the string. I can't build again the engine and I'm not going to do that.
 I'm trying to solve my problem ;) If you have any ideas regarding my issue
 and not going in another way this would be very appreciated.

 Nitsan,

 I think it's because you're referencing the capture group with index
 instead of index 2. Also, I don't understand why you have the pipe
 (|) character in your regex string... is that part of your engine?

*cough*... I meant to say index 3 instead of index 2.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Thank you Todd, I also want to capture when I don't have the www in the
beginning of the URL.
For instance, try to execute your code with
$orig = 
'http://zshare.net/video/541070871c7a8d9chttp://www.zshare.net/video/541070871c7a8d9c
';

That's why I used (www\.|), but I'm not a regex expert and I'm sure there a
way better solutions to this problem.

On Fri, Mar 6, 2009 at 11:53 PM, haliphax halip...@gmail.com wrote:

 On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun nit...@binnun.co.il
 wrote:
  I'm not looking for other ideas, the main thing here is that I have about
  30-100 regex's in the database and the script fetches them and applies
 them
  to the string. I can't build again the engine and I'm not going to do
 that.
  I'm trying to solve my problem ;) If you have any ideas regarding my
 issue
  and not going in another way this would be very appreciated.

 Nitsan,

 I think it's because you're referencing the capture group with index
 instead of index 2. Also, I don't understand why you have the pipe
 (|) character in your regex string... is that part of your engine?

 This code:

 $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
 $matches = array();
 preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
 echo $matches[2];

 Grabs the correct match:

 541070871c7a8d9c

 The regex pattern works with the pipe char, but it is unnecessary and
 may lead to some strange behavior.

 Hope this helps,


 --
 // Todd



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 4:01 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote:
 On Fri, Mar 6, 2009 at 11:53 PM, haliphax halip...@gmail.com wrote:

 On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun nit...@binnun.co.il
 wrote:
  I'm not looking for other ideas, the main thing here is that I have
  about
  30-100 regex's in the database and the script fetches them and applies
  them
  to the string. I can't build again the engine and I'm not going to do
  that.
  I'm trying to solve my problem ;) If you have any ideas regarding my
  issue
  and not going in another way this would be very appreciated.

 Nitsan,

 I think it's because you're referencing the capture group with index
 instead of index 2. Also, I don't understand why you have the pipe
 (|) character in your regex string... is that part of your engine?

 This code:

 $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
 $matches = array();
 preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
 echo $matches[2];

 Grabs the correct match:

 541070871c7a8d9c

 The regex pattern works with the pipe char, but it is unnecessary and
 may lead to some strange behavior.

 Thank you Todd, I also want to capture when I don't have the www in the
 beginning of the URL.
 For instance, try to execute your code with
 $orig = 'http://zshare.net/video/541070871c7a8d9c';

 That's why I used (www\.|), but I'm not a regex expert and I'm sure there a
 way better solutions to this problem.

http://www.regular-expressions.info is your best friend. Spend an
afternoon playing around on it... that's really the only advantage I
have over someone who hasn't.

Anyway, you can make that entire group optional with the ? character like so:

#http://(www\.)?zshare\.net/video/([^/]+)#

And if you don't want it to be captured, making the URL suffix index 1
instead of index 2, do this:

#http://(?:www\.)?zshare\.net/video/([^/]+)#

Any group that begins with ?: will not be captured in a match index. To recap:

$pattern = '#http://(?:www\.)?zshare\.net/video/([^/]+)#';
$orig = 'http://zshare.net/video/541070871c7a8d9c';
$matches = array();
preg_match($pattern, $orig, $matches);
echo $matches[1] . \n;
$orig = 'http://www.zshare.net/video/541070871c7a8d9c';
preg_match($pattern, $orig, $matches);
echo $matches[1] . \n;

Produces this output:

541070871c7a8d9c
541070871c7a8d9c

Hope this helps,


-- 
// Todd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Got it, thank you Todd.

I usually tend to use string based functions instead of regex, but sometimes
regex is a better option.

On Sat, Mar 7, 2009 at 12:16 AM, haliphax halip...@gmail.com wrote:

 On Fri, Mar 6, 2009 at 4:01 PM, Nitsan Bin-Nun nit...@binnun.co.il
 wrote:
  On Fri, Mar 6, 2009 at 11:53 PM, haliphax halip...@gmail.com wrote:
 
  On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun nit...@binnun.co.il
  wrote:
   I'm not looking for other ideas, the main thing here is that I have
   about
   30-100 regex's in the database and the script fetches them and applies
   them
   to the string. I can't build again the engine and I'm not going to do
   that.
   I'm trying to solve my problem ;) If you have any ideas regarding my
   issue
   and not going in another way this would be very appreciated.
 
  Nitsan,
 
  I think it's because you're referencing the capture group with index
  instead of index 2. Also, I don't understand why you have the pipe
  (|) character in your regex string... is that part of your engine?
 
  This code:
 
  $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
  $matches = array();
  preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig,
 $matches);
  echo $matches[2];
 
  Grabs the correct match:
 
  541070871c7a8d9c
 
  The regex pattern works with the pipe char, but it is unnecessary and
  may lead to some strange behavior.
 
  Thank you Todd, I also want to capture when I don't have the www in the
  beginning of the URL.
  For instance, try to execute your code with
  $orig = 'http://zshare.net/video/541070871c7a8d9c';
 
  That's why I used (www\.|), but I'm not a regex expert and I'm sure there
 a
  way better solutions to this problem.

 http://www.regular-expressions.info is your best friend. Spend an
 afternoon playing around on it... that's really the only advantage I
 have over someone who hasn't.

 Anyway, you can make that entire group optional with the ? character like
 so:

 #http://(www\.)?zshare\.net/video/([^/]+)#

 And if you don't want it to be captured, making the URL suffix index 1
 instead of index 2, do this:

 #http://(?:www\.)?zshare\.net/video/([^/]+)#

 Any group that begins with ?: will not be captured in a match index. To
 recap:

 $pattern = '#http://(?:www\.)?zshare\.net/video/([^/]+)#';
 $orig = 'http://zshare.net/video/541070871c7a8d9c';
 $matches = array();
 preg_match($pattern, $orig, $matches);
 echo $matches[1] . \n;
 $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
 preg_match($pattern, $orig, $matches);
 echo $matches[1] . \n;

 Produces this output:

 541070871c7a8d9c
 541070871c7a8d9c

 Hope this helps,


 --
 // Todd