PHP - Eregi To Preg_match
Code: [Select]
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ //email was valid } Trying to replace the eregi function with preg_match but i dont think its working. This is what i got: Code: [Select] if(preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ //this email is valid } What ever the content of $email in the preg_match version, it simply returns true... is the pattern wrong for preg_match? (patterns are no strong point of mine at the moment) Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315924.0 I noticed eregi is deprecated, what would I use instead? IS it reliable to use eregi() to prevent email injection? if (eregi("(\r|\n)", $first) || eregi("(\r|\n)", $second)){ die("Spammer detected"); }else{ //do this }; Helo, I need big help how to adjust this code to new PHP 5.3 that dont support egeri any more public static function blacklist(&$query) { return eregi(self::$_blacklist, $query) ? true : false; } HELP ! ! ! I am having trouble trying to fix my eregi call in my script. I have a reporting tool that grabs information from the user agent when they email help questions. I used eregi to find the string in an array and print out when it finds a match. I don't fully understand the PCRE functions so i don' t know if i am using them right. what i have is foreach($OSList as $CurrOS=>$Match) { // Find a match if (eregi($Match, $_SERVER['HTTP_USER_AGENT'])) { // We found the correct match break; } } I know i need to change this around for PCRE preg_match maybe but i am not sure. if anyone could send me a tutorial or help me out it would be great. EDIT: notice the foreach was not correct This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346108.0 Which is most efficient for finding a string within a string? Eregi or strpos? Currently im using Eregi to check a string again an array of blocked words and retrun true if one is present. But it seems i can do it also with strpos... so which is best function to use ? Hello.I got some error in my code: Deprecated: Function eregi() is deprecated in config.php on line 84 This is my code if(!eregi( "^[a-zA-Z\-_0-9/-]+$", $type )) unset($type); if(!eregi( "^[a-zA-Z\-_0-9/]+$", $act )) unset($act); if(!eregi( "^[a-zA-Z\-_0-9/]+$", $id )) unset($id); Can someone help me what should be changed here my code <html> <head><title>TESTING</title></head> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"/> email: <input type=text name=email value="" /><br/> feedback: <input type=text name=ex value=""/><br/> <input type="submit" value="submit" /><br/> </body> </html> <?php $email = $_GET['email']; $ex = $_GET['ex']; if(!eregi('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z]+$',$email)){ echo 'invalid email address<br/>'; } else { echo 'good to go<br/>'; } if(eregi('money|brooklyn|new york' ,$ex)){ echo '1'; } else { echo '0'; } ?> The code works fine but when i put on my error reporting i get that eregi is deprecated, now if eregi is depreciated which function should i use ? or should i just suppress the error ? I'm sure this issue has been addressed before, but as I can't find anything on google OR bing, I've resorted to asking it he Since, ereg and eregi are deprecated in PHP5, how do you test strings using regular expressions? Is there a new function for this? EDIT: I also looked on php.net, but all it says is its deprecated in PHP5. I didn't see any links to the new function(s) that have replaced the former. Hi Guys,
Firstly I would like state that I do not have a clue about PHP coding, I have merely signed up to gain some help with the following errors I have with my site I have recently setup with a PHP sports application.
I downloaded the application from the following website http://phpmysport.sourceforge.net/ and as far as I know the software is opensource and no longer supported by its developer.
The following http://www.proevoeliteleagues.esy.es/ is my website which displays the error messages.
Please see following code the files in question:
menu.php
<?php /* * phpMySport : website for team sport clubs and leagues * * Copyright (C) 2006-2009 Jerome PLACE. All rights reserved. * * Email : djayp [at] users.sourceforge.net * Website : http://phpmysport.sourceforge.net * Version : 1.4 * Last update : 4 march 2009 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /****************************/ /* MENUS */ /****************************/ $file=ROOT."/menu.csv"; # file containing the website menu # list of default pages $default_pages=array( array('level'=>'parent','title'=>$lang['general']['home'],'url'=>'index.php','class'=>'menu_home'), array('level'=>'parent','title'=>$lang['general']['news'],'url'=>'index.php?r='.$lang['general']['idurl_news'].'&v1=news_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['information'],'url'=>'index.php?r='.$lang['general']['idurl_information'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['team_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=team_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['member_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=member_list','class'=>''), array('level'=>'child','title'=>$lang['general']['member_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=member_list','class'=>''), array('level'=>'child','title'=>$lang['general']['player_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=player_list','class'=>''), array('level'=>'child','title'=>$lang['general']['manager_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=manager_list','class'=>''), array('level'=>'child','title'=>$lang['general']['coach_list'],'url'=>'index.php?r='.$lang['general']['idurl_team'].'&v1=coach_list','class'=>''), array('level'=>'child','title'=>$lang['general']['referee_list'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=referee_list','class'=>''), array('level'=>'parent','title'=>$lang['general']['match_list'],'url'=>'index.php?r='.$lang['general']['idurl_match'],'class'=>''), array('level'=>'child','title'=>$lang['general']['match_list'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=match_list','class'=>''), array('level'=>'child','title'=>$lang['general']['standings'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=standings','class'=>''), array('level'=>'child','title'=>$lang['general']['stats_player'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=stats_player','class'=>''), array('level'=>'parent','title'=>$lang['general']['competition_list'],'url'=>'index.php?r='.$lang['general']['idurl_competition'].'&v1=competition_list','class'=>''), //array('order'=>'6.1','title'=>$lang['general']['statistics'],'url'=>'index.php?r='.$lang['general']['idurl_match'].'&v1=statistics','class'=>''), //array('order'=>'8.0','title'=>$lang['general']['search_member'],'url'=>'index.php?r='.$lang['general']['idurl_member'].'&v1=search_member','class'=>''), array('level'=>'parent','title'=>$lang['general']['club_list'],'url'=>'index.php?r='.$lang['general']['idurl_club'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['field_list'],'url'=>'index.php?r='.$lang['general']['idurl_field'],'class'=>''), array('level'=>'parent','title'=>$lang['general']['forum_list'],'url'=>'index.php?r='.$lang['general']['idurl_forum'],'class'=>'') ); $website_menu=array(); # we load the menu if(file_exists($file) AND $fp=fopen($file, "r") AND filesize($file)!=0) { $i=0; while (($data = fgetcsv($fp, 1000, ";")) !== FALSE) { $website_menu[$i]['level']=$data[0]; $website_menu[$i]['title']=$data[1]; $website_menu[$i]['url']=$data[2]; $website_menu[$i]['class']=$data[3]; $website_menu[$i]['target']=$data[4]; $i++; } fclose($fp); } else { $website_menu=$default_pages; } $k=0; $i=-1; foreach($website_menu AS $value) { if(!isset($value['target'])) $value['target']=''; if(!eregi("http",$value['url'])) { $value['url']=convert_url($value['url']); } if($value['level']=='parent') { $i++; $j=0; $index['menu'][$i]=$value; $index['menu'][$i]['i']=$k; $index['menu'][$i]['submenu']=array(); } else { $index['menu'][$i]['submenu'][$j]=$value; $index['menu'][$i]['submenu'][$j]['i']=$k; $j++; } $k++; } /* # team of the club $index['team']=array(); if(CLUB!=0) { if(!isset($_SESSION['menu_team'])) { $var['condition']=""; $var['limit']=""; $var['order']=" ORDER BY e.sex_id, ne.team_name_name ASC"; $included=1; include_once(create_path("team/sql_team.php")); include_once(create_path("team/tpl_team.php")); include_once(create_path("team/lg_team_".LANG.".php")); include(create_path("team/team_list.php")); unset($included); $_SESSION['menu_team']=$page['team']; } $index['team']=$_SESSION['menu_team']; } # information pages list $index['information']=array(); if(!isset($_SESSION['menu_information'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("information/sql_information.php")); include_once(create_path("information/tpl_information.php")); include_once(create_path("information/lg_information_".LANG.".php")); include(create_path("information/page_list.php")); unset($included); $_SESSION['menu_information']=$page['page']; } $index['information']=$_SESSION['menu_information']; # forums list $index['forum']=array(); if(!isset($_SESSION['menu_forum'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("forum/sql_forum.php")); include_once(create_path("forum/tpl_forum.php")); include_once(create_path("forum/lg_forum_".LANG.".php")); include(create_path("forum/forum_list.php")); unset($included); $_SESSION['menu_forum']=$page['forum']; } $index['forum']=$_SESSION['menu_forum']; # competition list $index['competition']=array(); if(!isset($_SESSION['menu_competition'])) { $var['condition']=""; $var['limit']=""; $var['order']=""; $included=1; include_once(create_path("competition/sql_competition.php")); include_once(create_path("competition/tpl_competition.php")); include_once(create_path("competition/lg_competition_".LANG.".php")); include(create_path("competition/competition_list.php")); unset($included); $_SESSION['menu_competition']=$page['competition']; } $index['competition']=$_SESSION['menu_competition']; # plugins $index['plugin']=array(); $nb_plugin=sizeof($plugin); $j=0; for($i=0; $i< $nb_plugin; $i++) { if($plugin[$i]['active']==1) { $index['plugin'][$j]['name']=$plugin[$i]['name']; $index['plugin'][$j]['link']=$plugin[$i]['link']; $index['plugin'][$j]['class']=$plugin[$i]['class']; $j++; } } #text $index['L_home']=$lang['general']['home']; $index['L_news']=$lang['general']['news']; $index['L_information']=$lang['general']['information']; $index['L_member']=$lang['general']['member']; $index['L_member_list']=$lang['general']['member_list']; $index['L_player_list']=$lang['general']['player_list']; $index['L_manager_list']=$lang['general']['manager_list']; $index['L_coach_list']=$lang['general']['coach_list']; $index['L_referee_list']=$lang['general']['referee_list']; $index['L_match']=$lang['general']['match']; $index['L_match_list']=$lang['general']['match_list']; $index['L_standings']=$lang['general']['standings']; $index['L_stats_player']=$lang['general']['stats_player']; $index['L_competition_list']=$lang['general']['competition_list']; $index['L_team_list']=$lang['general']['team_list']; $index['L_statistics']=$lang['general']['statistics']; $index['L_search_member']=$lang['general']['search_member']; $index['L_club_list']=$lang['general']['club_list']; $index['L_view_club']=$lang['general']['view_club']; $index['L_field_list']=$lang['general']['field_list']; $index['L_forum_list']=$lang['general']['forum_list']; */ # mode club $index['link_view_club']=""; $index['class_view_club']=""; if(CLUB!=0){ $index['link_view_club']=convert_url("index.php?r=".$lang['general']['idurl_club']."&v1=view&v2=".CLUB); $index['L_club_list']=$lang['general']['club_opponent_list']; $index['L_information']=$lang['general']['the_club']; if(isset($_GET['r']) AND $_GET['r']==$lang['general']['idurl_club'] AND isset($_GET['v2']) AND $_GET['v2']==CLUB) { $index['class_information']="on"; $index['class_club']=""; } } ?>fonctions.php Im new to php and Im working on a script that I purchased. I'm getting this error when I try to setup my script. I did some research and understand that I "eregi" is old code and not being used anymore. So I tried to use preg_match but I'm stuck. If anyone can look at the code and help with some notes. I would like to understand what im doing wrong not just a fix. Deprecated: Function eregi() Code: [Select] if (eregi($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; This is what I get when using preg_match. preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash Code: [Select] if (preg_match($file,$_SERVER["HTTP_ACCEPT_LANGUAGE"]) && !$use_lang) $use_lang = $file; Hi guys, I have been using this code: preg_match('/<h2>(.*?)<\/h2>/', $data, $matches); which i changed to: $tag1 = 'h2'; $tag2 = 'h2'; preg_match('/$tag1(.*?)$tag2/', $data, $matches); however i need it to work allowing variables (of any character or symbol) within $tag1. I tried $tag1 = 'h(.*?)2'; $tag2 = 'h2'; preg_match('/$tag1(.*?)$tag2/', $data, $matches); but that does not work .... essentiall the whole thing would work like this (example only): firstpartoftag1VARIABLE1lastpartoftag1VARIABLE2tag2 ps the preg_match should only capture the VARIABLE2 data not VARIABLE1 any ideas or help would be much appreciated cheers in advance Why dosent this work, im trying to match upper case, lower case and numbers only Code: [Select] $id = '3xDJ7@#'; if (!preg_match('/^[a-zA-Z0-9]/', $id)){ echo "ERROR!"; }else{ echo 'ok'; } This always echos "ok" Hey guys, In my contact form i have the action: preg_match but i've come accross a problem. Problem: Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\Program Files (x86)\wamp\www\ts\contact.php on line 34 Code:$error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; Thanks in advance I've tried alot of different ways, google, but just can't find the correct way to do this.. I'm trying to search for a word in an inputted string.. here's the code <html> <head><title>TESTING</title></head> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"/> email: <input type=text name=email value="" /><br/> feedback: <input type=text name=ex value=""/><br/> <input type="submit" value="submit" /><br/> </body> </html> <?php $email = $_GET['email']; $ex = $_GET['ex']; $pattern = '/^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z]+$/'; //$pattern1 = '/nprezident/prezident/'; if(!preg_match($pattern, $email)){ echo 'invalid email address<br/>'; } else { echo 'good to go<br/>'; } if(preg_match('/nprezident/,/prezident/', $ex)){ echo 'just something about that sentence is nice'; } else { echo 'no good'; } ?> Ok the one I'm having a problem with is the second preg_match when trying to search for two words i can get one word to print but when i use add a second word it gives an error. How do i add a second word? information.txt <li><img src="http://www.lol.com" alt="0" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="4" /></li> <li><img src="http://www.lol.com" alt="9" /></li> <li><img src="http://www.lol.com" alt="1" /></li> <li><img src="http://www.lol.com" alt="7" /></li> <li><img src="http://www.lol.com" alt="2" /></li> How can I get the alt="$ValueIwant" for each with a preg_match I'm pretty new to this, How exactly could i get the text between the www. and .com? so if i have a url: http://www.facebook.com I want to just return "facebook" in my site search some of the results come out still with html. i have used the strip tags function but how would i use the preg_match function to get rid of the "> still left over? Im trying to match this string, but i dont wat to match normal words like "hello world 646" Code: [Select] $string = "2ab055843241f20044af82ae0d5ace04"; //always over 15 chars - without spaces if ( preg_match('~^[0-9\s]+$~D', $string)) { echo 'yes'; } If i can do it with preg_match that would be great |