473,387 Members | 1,641 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,387 software developers and data experts.

ereg conversion to preg_match help

201 100+
hello -

i need to convert this string to preg_match to support current version of php. i have googled and found some info but still get an error where it doesnt like my search string.

Expand|Select|Wrap|Line Numbers
  1. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $call_function)) 
  2.  
thanks in advance for your help,

theo werntz ii
Dec 16 '09 #1
3 3529
Atli
5,058 Expert 4TB
Hey.

Your use of the $HTTP_USER_AGENT is most likely not going to work on 5.3 (or any version after 4.2). You should be using $_SERVER['HTTP_USER_AGENT'] instead.
This is because of the register_globals directive, which was used in the past to extract all $_REQUEST, $_COOKIE and $_SERVER variables into the global scope. This has been deprecated since 4.2, and will be removed in 6.0, so it is best to not rely on it.

As to your regexp, these two if blocks produce the same results in 5.3: (Tested them in Opera 10.10... which oddly enough identifies itself as Opera 9.80...)
Expand|Select|Wrap|Line Numbers
  1. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'], $matches)) {
  2.     var_dump($matches);
  3. }
  4.  
  5. if (preg_match('#Opera(/| )([0-9]\.[0-9]{1,2})#i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
  6.     var_dump($matches);
  7. }
The PCRE (preg) pattern is a little different, but not so much that it should be hard to convert old POSIX (ereg) expressions. Just takes a bit of Googling :)
Dec 17 '09 #2
wizardry
201 100+
thanks alti will try and repost latter my results!
Dec 17 '09 #3
wizardry
201 100+
Thanks alti -

this has been completed for some time now.
Jan 15 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
2
by: pomho | last post by:
Hi all, Even having read the PHP Manual, I can't understand the difference between the ereg function and the preg_match... Could anyone help ? thx in advance, --
3
by: Aphrael | last post by:
Hello all, last time, ereg specialists did help me, so I ask again: base pattern: some texte her result: the number alone So ? any idea ? Aphrael ;-)
3
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
4
by: ollie.mitch | last post by:
Hi, I need two ereg expressions in my PHP code. One of them needs to check that a string only contains letters, and the other needs to check that the string only contains letters and commas...
2
by: dkirkdrei | last post by:
I am having a problem verifying characters in a variable, I am trying to create a conditional statement based on whether or not the first two characters of a variable contain "E9". The variable...
3
by: monomaniac21 | last post by:
hi all can anyone tell me, does this condition evaluate to true or false? $foo = ereg('ca?t', 'caaaaaaat'); thanks marc
5
by: The Big One | last post by:
8-7-2008 Hello, Our hosting provider has changed his server to PHP5. I have a PHP file that normaly gives the custumor an email, and i get one mail. Now the server has changed i only get my...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.