Php error need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Php error need help

Post by sjakalen »

I have 2 more errors since update from php 5.2 to 5.3 and I hope someone can help me
The error is
1.
PHP Deprecated: Function ereg() is deprecated in products.php on line 35
2.
PHP Deprecated: Function ereg() is deprecated in cart_add.php on line 23
1 code

Code: Select all

 
        foreach ($_GET as $key => $value) {
          if ( (ereg('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName()) ) {
            $id = $key;
          }
2 Code

Code: Select all

 
        foreach ( $_GET as $key => $value ) {
          if ( (is_numeric($key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName()) ) {
            $id = $key;}
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: Php error need help

Post by Weiry »

You should try using preg_match()
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

Like this?

Code: Select all

if ( (preg_match()('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || preg_match()('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName()) ) {
I don't think it works, did I do something wrong?
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Php error need help

Post by aravona »

Code: Select all

preg_match('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || preg_match('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName())
I think you had too many brackets before :)
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Php error need help

Post by dejvos »

Pleas look for preg_match() in PHP documentation

http://cz.php.net/manual/en/function.preg-match.php

and the depracated is not a quite an error it means that:
http://en.wikipedia.org/wiki/Deprecation
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

That don't work it give me another error on the same line any Idea?

PHP Parse error: syntax error, unexpected T_STRING, expecting '(' in /customers/indoexport.eu/indoexport.eu/httpd.www/includes/content/products/products.php on line 35

Code: Select all

         if ( (preg_match('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || preg_match('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName()) {
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Php error need help

Post by aravona »

It means you have a ( in the wrong place or there is one missing. Go through and check each open bracket has a closing bracket to partner with. The error pretty much tells you that.

preg_match() doesnt need to sit inside brackets like you have it. Did you read the manual linked now for the third time? http://cz.php.net/manual/en/function.preg-match.php

Code: Select all

if ( preg_match('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || preg_match('^[a-zA-Z0-9 -_]*$', $key) && ($key != $osC_Session->getName())
Try that. The IF opens around the preg_match, the preg_match contains what it needs to contain - then closes, new preg_match with its own information, then the bit with the get name, closes the IF.

Should work. Counting brackets is annoying but you really can double check that yourself.
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

I did reed the manuel but I am no expert, and I did not understant it very wel, I'm sorry
I stil can't make it work :(
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

I did get some response doing like this

Code: Select all

if (preg_match('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || 
preg_match('^[a-zA-Z0-9 -_]*$', $key) && ($key != $osC_Session->getName)) {
But my product was not found and thise error was posted

PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: No ending delimiter '^' found in products.php on line 36
PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: No ending delimiter '^' found in products.php on line 35

I don't get it :(
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Php error need help

Post by flying_circus »

Code: Select all

if (preg_match('/^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $key) || 
preg_match('/^[a-zA-Z0-9 -_]*$/', $key) && ($key != $osC_Session->getName)) {
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

Hi FC
Working but post an error
PHP Notice: Undefined property: osC_Session_database::$getName in products.php on line 36
What is that about?
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

I got it () after getname :)
Now it works
Thanks
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

Can you help with my last error

Code: Select all

foreach ( $_GET as $key => $value ) {
3.          if ( (is_numeric($key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && ($key != $osC_Session->getName()) ) {
4.            $id = $key;}
sjakalen
Forum Newbie
Posts: 13
Joined: Sat Feb 06, 2010 7:48 pm

Re: Php error need help

Post by sjakalen »

I got that to,,
Im getting good at this

Code: Select all

if ( (is_numeric($key) || preg_match('/^[a-zA-Z0-9 -_]*$/', $key)) && ($key != $osC_Session->getName()) ) {
I thinkit is ok
Post Reply