PHP - Eregi Or Strpos ?
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 ? Similar TutorialsHi, I'll be honest don't have a clue what I am doing but a friend asked me to look into her site, she gets the following error at the top of this page http://www.morairaluxuryvillas.com/rentals/villalist.php Warning: strpos() [function.strpos]: Offset not contained in string in /home/morairal/public_html/rentals/villalist.php on line 85 the code on the line 85 is: $secondfstemp = strpos($block1, ".", $firstfs); I am more than willing to look into but don't know where to start - anyone have any ideas? Thanks for your time:-) Hi Guys I've been trying to work on my OS Commerce site, but for some reason I'm getting this error on the main index.php page. Welcome Guest! Would you like to log yourself in? Or would you prefer to create an account? Feel free to click any of the links below to access the main categories. Warning: strpos() [function.strpos]: Empty delimiter. in /var/www/vhosts/XXXXXX.co.uk/httpdocs/shop/index.php on line 319 319 shows this: if (isset($cPath) && strpos('_', $cPath)) { Any ideas where this error comes from? 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 }; This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346108.0 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 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 ! ! ! 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) 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 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 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 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. Hey guys I need some help I did a quick search and couldn't find my problem so I hope I didn't miss it. Anyways, I've got a bit of code in which when a specific website is visited, it generates a log. This is to track the number of times the website gets visited and from where. I know this sounds like a counter, but it's different. I'm having a problem though, because right now, I can't get it to generate for ONLY the website entered. It generates for EVERY website instead of just the specific one. Right now this is what I have.. if (strpos($_url, "MY_SPECIFIC_WEBSITE") //URL { I've tried adding to it to fix it, but I'm obviously still learning PHP and am sick of strugglnig. If anyone could please help I would appreciate it so much. Hi Im having a problem finding the posistion of a div tag I tried this piece of code $fpos= strpos($snip, "<div id=\"footer\">") Then this piece $fpos= strpos($snip, "<div id="footer">") The $snip is the entire html document I thought maybe the \ might be causeing problem but without it Then i tried this any suggestions guys Thanks James Hello, Am a little puzzled on how to effectively determine if a character exists in a string. I am trying to come to grips with the function strpos but its a little confusing. If am searching for an underscore in a string and want to echo yes if the string contains an underscore, would the code below be right? Would it be right to exclude booleans TRUE and FALSE Example 1 Code: [Select] <?php $string = "Hello_World"; if(strpos($string, "_")) { echo "yes"; } OR do I have to include the booleans TRUE/FALSE Example 2 Code: [Select] <?php $string = "Hello_World"; if(strpos($string, "_") == TRUE) { echo "yes"; } How do I do two strpos conditions? here is kinda what I have.... if (strpos($val,'Sparring') && ($val,'Ecas') { } 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; This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315924.0 I have a string like this: Code: [Select] $data = "<a href="">Arbitrary characters. Bla bla bla</a><p>123456789</p><p>$10,100</p><p>01/02/2010</p><p>01/02/2011</p>"; What I am trying to accomplish is to extract the number between the first <p> tags as well as the date between the last <p> tags. I can extract the first number just fine by doing this: Code: [Select] $opening_p = strpos($data, '<p>'); $opening_p += 3; $closing_p = strpos($data, '</p>'); $length = $closing_p - $opening_p; // The length of the number changes, so I need to know the current length $first_number = substr($data, $opening_p, $length); However, no matter what I do, the position for the fourth <p> comes out to be the same as the first <p> In other words, this produces exactly the same number for the <p> Code: [Select] $opening_fourth_p = strpos($data, '<p>', 4); $opening_fourth_p += 3; So even with the offset in strpos, the position is exactly the same for both "extractions". So to conclude, both of these returns the same value: Code: [Select] $opening_p = strpos($data, '<p>'); $opening_fourth_p = strpos($data, '<p>', 4); Is there something I miss? This will be an easy one for you guys...
One of the fields in a MySQL database is a varchar() that was populated using a checkbox method and can contain more than one response. in this case i have blue, yellow, green and want to check if the field contains blue before echoing the statement to the screen. How would i use strpos in this case? ive tried a few thigns and get syntax error. The below of course works if the field ONLY contains blue. if (($row['colorsyoulike']) =='blue') { echo "<tr>"; echo "<td>Blue is an available Color!</td>"; } thanks. |