[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


eregi to pregmatch problems

Posted on 2012-09-15
Medium Priority
Last Modified: 2016-03-25
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,
Question by:Oliver2000
  • 5
  • 4
LVL 12

Expert Comment

ID: 38402483
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
LVL 111

Expert Comment

by:Ray Paseur
ID: 38403616
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:

Author Comment

ID: 38405161
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));
	$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:

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:
$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.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 38405210
Please see: http://www.laprbass.com/RAY_temp_oliver2000.php
<?php // RAY_temp_oliver2000.php

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

$arr = explode(DIRECTORY_SEPARATOR, $url);

$INTERNAL_PAGE = array_pop($arr);
$USERID        = array_pop($arr);
$LANGUAGE      = array_pop($arr);


Open in new window

HTH, ~Ray

Author Closing Comment

ID: 38406875
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.
LVL 111

Expert Comment

by:Ray Paseur
ID: 38406937
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?

Author Comment

ID: 38407629
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.
LVL 111

Expert Comment

by:Ray Paseur
ID: 38408904
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
LVL 111

Expert Comment

by:Ray Paseur
ID: 41523159
More than three years later and no answer!

Author Comment

ID: 41523203
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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 12 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question