PHP Web Host - Quality Web Hosting For All PHP Applications Sign up for PayPal and start accepting credit card payments instantly
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
montego
Former Admin in Good Standing


Joined: Aug 29, 2004
Posts: 9070
Location: Arizona

PostPosted: Thu Jan 21, 2010 7:41 am Reply with quote Back to top

I was referring to the "i" that you added to the end of the search pattern.

So, if you wanted to use preg_match and look for that exact match (ALL CAPS) rather than also finding "MsiE" for example), remove the 'i' like this:

Code:

if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {


I am just letting you know that what you wrote is NOT 100% the same as the ereg is all.

In addition, this would be faster, but less flexible:

Code:

if (strpos('MSIE', $_SERVER['HTTP_USER_AGENT'])) {
View user's profile Send private message Visit poster's website
jalaklenteng
New Member
New Member


Joined: Feb 18, 2010
Posts: 1

PostPosted: Thu Feb 18, 2010 8:11 pm Reply with quote Back to top

Palbin wrote:
Look in rnconfig.php for $error_reporting = E_ALL^E_NOTICE; (around line 82) and change it to this $error_reporting = E_ALL^E_NOTICE^E_DEPRECATED;


where i can find the rnconfig.php?
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2403
Location: Pennsylvania

PostPosted: Thu Feb 18, 2010 9:04 pm Reply with quote Back to top

It should be in the root directory of your site. Where config.php resides.
View user's profile Send private message Visit poster's website
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Tue Apr 13, 2010 1:33 am Reply with quote Back to top

Thanks for your explanation montengo. Let's see if I got the point

Example
Code:
if (ereg('IIS', $_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['SCRIPT_NAME'])) {


Replace with
Code:
if (preg_match('/IIS/', $_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['SCRIPT_NAME'])) {


Is this correct?

I would like to correct this group of lines. Can you give me an example?

Code:
function check_words($Message) {
   global $CensorMode, $CensorReplace, $EditedMessage, $CensorList;
   include_once(INCLUDE_PATH.'config.php');
   $EditedMessage = $Message;
   if ($CensorMode != 0) {
      if (is_array($CensorList)) {
         $Replace = $CensorReplace;
         if ($CensorMode == 1) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("$CensorList[$i]([^a-zA-Z0-9])","$Replace\\1",$EditedMessage);
            }
         } elseif ($CensorMode == 2) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("(^|[^[:alnum:]])$CensorList[$i]","\\1$Replace",$EditedMessage);
            }
         } elseif ($CensorMode == 3) {
            for ($i = 0; $i < count($CensorList); $i++) {
               $EditedMessage = eregi_replace("$CensorList[$i]","$Replace",$EditedMessage);
            }
         }
      }
   }
   return $EditedMessage;
}
View user's profile Send private message
montego
Former Admin in Good Standing


Joined: Aug 29, 2004
Posts: 9070
Location: Arizona

PostPosted: Sat Apr 17, 2010 4:50 pm Reply with quote Back to top

unicornio, try something like this:

Code:

$EditedMessage = preg_replace("/$CensorList[$i]([^a-zA-Z0-9])/i","$Replace\\1",$EditedMessage);


See if that works.
View user's profile Send private message Visit poster's website
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Sat Apr 24, 2010 9:15 am Reply with quote Back to top

montego,

Thanks, I understood already what was the differents between sensitive and insensitive.

What you wrote above is really important for me now.

Quote:
In addition, this would be faster, but less flexible:

if (strpos('MSIE', $_SERVER['HTTP_USER_AGENT'])) {



Are you telling me pre_match is not faster than strpos. Can you please explain to me when you need to use it and why it is more fast.

Question Question Question Question
View user's profile Send private message
jakec
Site Admin


Joined: Feb 06, 2006
Posts: 3028
Location: United Kingdom

PostPosted: Sat Apr 24, 2010 10:11 am Reply with quote Back to top

unicornio wrote:

Are you telling me pre_match is not faster than strpos. Can you please explain to me when you need to use it and why it is more fast.


If you search the internet you will find many articles benchmarking strpos against preg_match.
View user's profile Send private message
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Sun May 02, 2010 4:31 am Reply with quote Back to top

Hi everybody

I am getting an error when I want to conver this line


Code:
         elseif (eregi("http://", $user_avatar)) {


it became this

Code:
         elseif (preg_match("/http:///i", $user_avatar)) {


but I get one error from here
Only registered users can see links on this board!
Get registered or login to the forums!


Should I do it like this

Code:
         elseif (preg_match("/http://\/i", $user_avatar)) {


I did it but I still get the error.
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2403
Location: Pennsylvania

PostPosted: Sun May 02, 2010 9:10 am Reply with quote Back to top

elseif (preg_match("/http:\/\//i", $user_avatar)) {
View user's profile Send private message Visit poster's website
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Mon May 10, 2010 3:20 pm Reply with quote Back to top

Very Happy

Palbin, thanks. I understand now more about this issue. Everytime I find any different. lol. I guess I can convert them almost all but I was working right now on this one but I get access denied.

Code:
if ( !eregi( "mainfunctions.php", $PHP_SELF ) ) {

   die( "You can't access this file directly ..." );

}


I replaced with this one


Code:
if ( !preg_match( "/mainfunctions.php/i", $PHP_SELF ) ) {

   die( "You can't access this file directly ..." );

}


but unfortunatly I get You can't access this file directly when I go the module. I do know my server is running php as a CGI but I dont want to paste that code into the mainfile.php. What should do? I read all Access Denied here Very Happy but I didnt find anything like this.

Shocked Let me know please.
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2403
Location: Pennsylvania

PostPosted: Mon May 10, 2010 3:37 pm Reply with quote Back to top

If that is for a modules switch it over to use the constant.

if (!defined('MODULE_FILE')) {
die ("You can't access this file directly...");
}
View user's profile Send private message Visit poster's website
slackervaara
Worker
Worker


Joined: Aug 26, 2007
Posts: 234

PostPosted: Mon Jun 14, 2010 12:54 am Reply with quote Back to top

Which program do you recommend to make such substitions in multiple files in Linux?
I have been thinking about regexxer.
View user's profile Send private message
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Wed Jun 16, 2010 2:40 pm Reply with quote Back to top

Is there any tool for windows?
View user's profile Send private message
slackervaara
Worker
Worker


Joined: Aug 26, 2007
Posts: 234

PostPosted: Thu Jun 17, 2010 12:40 am Reply with quote Back to top

Maybe Replace Text might work and it is freeware.
Only registered users can see links on this board!
Get registered or login to the forums!
View user's profile Send private message
gregexp
The Mouse Is Extension Of Arm


Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Thu Jun 17, 2010 11:57 pm Reply with quote Back to top

For linux, I recommend you become familiar with the command: sed


As for the php version of all this, I was wondering if anyone considered having apd installed?

I'm thinking it might be a bit much for the average user, or might be too much of a requirement, but if you happen to be able to install apd into your php install, you could make an include at the top of mainfile.php to override functions.php(example only).

Here's an example of the code I'd use for the eregi function:

Code:

override_function('eregi','$needle,$haystack','return rn_eregi($needle,$haystack);');

function rn_eregi($needle, $haystack){
return (preg_match("/".$needle."/i", $haystack));
}


rename_function("__overridden__", 'something_random');

override_function('ereg','$needle,$haystack','return rn_ereg($needle,$haystack);');

function rn_ereg($needle, $haystack){
return (preg_match("/".$needle."/", $haystack));
}

rename_function("__overridden__", 'something_else_random');



After you override a function, you have to undeclare the __overridden__ function, which I do by renaming it.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Fri Nov 05, 2010 7:19 pm Reply with quote Back to top

Depracated

Code:
if( !eregi( $MSAph, $msaurl ) )  {



Is this correct

Code:
if( !stripos( $MSAph, $msaurl ) )  {


Help to convert this line if it is wrong. Thanks in advance,
View user's profile Send private message
PHrEEkie
Subject Matter Expert


Joined: Feb 23, 2004
Posts: 358

PostPosted: Fri Nov 05, 2010 11:06 pm Reply with quote Back to top

unicornio wrote:
Depracated

Code:
if( !eregi( $MSAph, $msaurl ) )  {



Is this correct

Code:
if( !stripos( $MSAph, $msaurl ) )  {


Help to convert this line if it is wrong. Thanks in advance,


As a coding preference, whenever I see/use a variable as the haystack, I always clearly separate it from the code for debugging purposes. Also, a variable MIGHT have characters in it from user input, which might crash a PCRE Regex. It's best to use preg_quote on the variable. It would all look like this:

Code:
SOLUTION CODE A:
if(!preg_match('/' . preg_quote($MSAph) . '/i',$msaurl)) {


If you are absolutely 100% positively sure that the variable is safe, then:

Code:
SOLUTION CODE B:
if(!preg_match('/' . $MSAph . '/i',$msaurl)){


Notice I am using single quotes to create strings for the delimiters. That is because I am separating the variable off by itself. If you want to write the most compact code, and again, this is a style/readability issue for other programmers who might wander into this line of code, you must use double quotes. Double quotes expand the variable, single quotes makes it literal.

Here are two compact examples, and how PHP would interpret them. Let's say $MSAph currently holds the value of SOMEDATA.

Code:
Double quoted:
if(!preg_match("/$MSAph/i",$msaurl)){

would be interpreted as:
if(!preg_match("/SOMEDATA/i",$msaurl)){


while
Code:
Single quotes:
if(!preg_match('/$MSAph/i,$msaurl)){

would be interpreted literally:
if(!preg_match('/$MSAph/i',$msaurl)){


In the last example, since the variable wasn't expanded, the REGEX is looking for the text msaph (the /i after the last delimiter makes the search case-insensitive, so the casing is made moot), and also it is looking for it at the FRONT of a string (the $). Clearly not what we want to accomplish. Although that example likely would NOT crash the script or produce any warning, it also isn't what we want. Understanding single and double quoted strings is essential to writing good code. Good luck!

- Keith
View user's profile Send private message
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Sat Nov 06, 2010 7:59 am Reply with quote Back to top

Create a new post for any other deprecated or warning
Only registered users can see links on this board!
Get registered or login to the forums!


Last edited by unicornio on Sat Nov 06, 2010 6:07 pm; edited 1 time in total
View user's profile Send private message
Guardian2003
Site Admin


Joined: Aug 28, 2003
Posts: 6299
Location: Vsetin, Czech Republic

PostPosted: Sat Nov 06, 2010 4:33 pm Reply with quote Back to top

unicornio to avoid confusing other readers, would you mind posting these in the PHP forum in the future, if the code is not specific to RN?
I am concerned people will come across this and then running off to apply these code changes to RN when it is not used within RN.
View user's profile Send private message Send e-mail Visit poster's website
unicornio
Involved
Involved


Joined: Aug 13, 2009
Posts: 410

PostPosted: Sat Nov 06, 2010 6:09 pm Reply with quote Back to top

it is already done. Thanks for warning me. I edited my last post.
View user's profile Send private message
djmaze
Subject Matter Expert


Joined: May 15, 2004
Posts: 689
Location: http://tinyurl.com/5z8dmv

PostPosted: Sun Nov 07, 2010 12:07 pm Reply with quote Back to top

Palbin wrote:
Look in rnconfig.php for $error_reporting = E_ALL^E_NOTICE; (around line 82) and change it to this $error_reporting = E_ALL^E_NOTICE^E_DEPRECATED;
mantasledge wrote:
Thanks Pablin! That fixed it Wink


It doesn't fix it, it only hides the issue Razz
View user's profile Send private message Visit poster's website
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2403
Location: Pennsylvania

PostPosted: Sun Nov 07, 2010 9:41 pm Reply with quote Back to top

I would have to question if it is actually an issue in the first place Wink
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum