eregi to pregmatch problems

Hi experts,

I try to convert some old eregi to preg_match which in most cases works for me but now I have to versions which I just cant get running.

The original is:
if (eregi('^/([a-z]*)/([a-z0-9\.,_~=&%-]+)/(.*)$', $PATH_INFO, $regs)) {

I tried now:
if (preg_match('/^/([a-z]*)/([a-z0-9\.,_~=&%-]+)/(.*)$/i', $PATH_INFO, $regs)) {

but I get the error UNKNOWN MODIFIER ( ?

Another one I dont get work is:
 if  ( eregi ('^(horosc|aries|aqua|cancer|capricornio|escorpiao|gemeos|libra|leao|peixes|sagitario|touro|virgem)',$INTERNAL_PAGE) ) {

I tried this one as well with / in the beginning and end but also shows up the same error with the unknown modifier.

Would be glad if somebody can help me with this...
Thanks in advance,
Oliver2000Asked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
Please see: http://www.laprbass.com/RAY_temp_oliver2000.php
<?php // RAY_temp_oliver2000.php
error_reporting(E_ALL);

// PARSE THIS URL STRING
$url = 'http://www.xxxxxxx.com/myscript.php/PT/000/obesidade_infantil.htm';

// BREAK STRING ON THE DIRECTORY SEPARATOR
$arr = explode(DIRECTORY_SEPARATOR, $url);

// GET THE LAST THREE POSITIONS
$INTERNAL_PAGE = array_pop($arr);
$USERID        = array_pop($arr);
$LANGUAGE      = array_pop($arr);

// SHOW THE WORK PRODUCT
var_dump($LANGUAGE, $USERID, $INTERNAL_PAGE);

Open in new window

HTH, ~Ray
0
 
zappafan2k2Commented:
Since you have slashes in the argument, I would use a different delimiter, like a pipe character.
if (preg_match('|^/([a-z]*)/([a-z0-9\.,_~=&%-]+)/(.*)$|i', $PATH_INFO, $regs))

Open in new window

Otherwise you have to escape the slashes.

More info here
0
 
Ray PaseurCommented:
Maybe if you can post some of the data and tell us what you're trying to select we could help.  The first character of a preg-type regular expression is the regex delimiter.  The next occurrence of the same character tells PHP that is the end of the regular expression, so any characters following would be the modifiers.  See the man pages linked here:
http://us2.php.net/manual/en/pcre.pattern.php
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Oliver2000Author Commented:
I tried alternativ with | but also not working.

The complete script looks like this:
// PART III :: Seassion Management & ensuring and evaluating the Path-Informations
if (eregi('^/([a-z]*)/([a-z0-9\.,_~=&%-]+)/(.*)$', $PATH_INFO, $regs)) {
	list($dummy, $LANGUAGE, $USRID, $INTERNAL_PAGE) = $regs;
	parse_str (urldecode($USRID));
 {$MODE='normal';}
	$INTERNAL_PAGE = str_replace ('=', '/', $INTERNAL_PAGE);
} else { echo "<meta http-equiv=refresh content=\"0; url=/index.php\">"; exit; }

Open in new window


what it does it to split my url:
http://www.xxxxxxx.com/myscript.php/PT/000/obesidade_infantil.htm

into $language, $userid, and page name ($internal_page)
further down in the same script I include the $internal_page at another place.

the results after this script should be with the example:
$LANGUAGE = 'PT'
$USERID = '000'
$INTERNAL_PAGE = 'obesidade_infantil.htm'

I never did this script and don't know really this kind of regex stuff but I switched server to new php and now the eregi isn't working anymore in some places. I appreciate your help.
0
 
Oliver2000Author Commented:
It was not what I planed to do but it did the job. I thought I change the eregi into preg_match but your solution helps me as well. Thank you for your help.
0
 
Ray PaseurCommented:
Please see: http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26

What was wrong with the solution?  I think it got exactly the right answers.  Why did you mark the grade down?
0
 
Oliver2000Author Commented:
Hi Ray,

Please check my initial question about TWO eregis which I needed to convert into preg_match versions. You helped me with the first part of the question but not with the second part because your solution was not the convertion for my eregi problem but a partial solution of one part of it. How ever your solution works perfectly as well for the first part of my problem.

I did solve in the meanwhile the second part as well.

Thanks once again for your help and solution.
0
 
Ray PaseurCommented:
Please give me a clue here... Tell me in plain language what this expression is intended to do.

 if  ( eregi ('^(horosc|aries|aqua|cancer|capricornio|escorpiao|gemeos|libra|leao|peixes|sagitario|touro|virgem)',$INTERNAL_PAGE) ) {

It might be as simple as this...

 if  ( preg_match('#^(horosc|aries|aqua|cancer|capricornio|escorpiao|gemeos|libra|leao|peixes|sagitario|touro|virgem)#i',$INTERNAL_PAGE) ) {

but once I understand the intent of the expression I will be better able to help.  Thanks, ~ray
0
 
Ray PaseurCommented:
More than three years later and no answer!
0
 
Oliver2000Author Commented:
Hi Ray, I wonder a little bit about your reply here. As explained at 2012-09-17 at 15:58:16 already I did mark B because what I got from you was not a complete solution but only in parts.

As explained in http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26 "B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem"

Either way Admin changed to A short after and there was nothing else to say about this question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.