Author |
Message |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Thu Jan 21, 2010 7:41 am |
|
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'])) {
|
|
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
jalaklenteng
New Member


Joined: Feb 18, 2010
Posts: 1
|
Posted:
Thu Feb 18, 2010 8:11 pm |
|
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? |
|
|
|
 |
Palbin
Site Admin

Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Thu Feb 18, 2010 9:04 pm |
|
It should be in the root directory of your site. Where config.php resides. |
_________________ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. |
|
|
 |
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm

Joined: Aug 13, 2009
Posts: 1123
|
Posted:
Tue Apr 13, 2010 1:33 am |
|
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;
}
|
|
|
|
|
 |
montego

|
Posted:
Sat Apr 17, 2010 4:50 pm |
|
unicornio, try something like this:
Code:
$EditedMessage = preg_replace("/$CensorList[$i]([^a-zA-Z0-9])/i","$Replace\\1",$EditedMessage);
|
See if that works. |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sat Apr 24, 2010 9:15 am |
|
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.
 |
|
|
|
 |
jakec
Site Admin

Joined: Feb 06, 2006
Posts: 3048
Location: United Kingdom
|
Posted:
Sat Apr 24, 2010 10:11 am |
|
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. |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sun May 02, 2010 4:31 am |
|
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
http:///
Should I do it like this
Code: elseif (preg_match("/http://\/i", $user_avatar)) {
|
I did it but I still get the error. |
|
|
|
 |
Palbin

|
Posted:
Sun May 02, 2010 9:10 am |
|
elseif (preg_match("/http:\/\//i", $user_avatar)) { |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Mon May 10, 2010 3:20 pm |
|
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 but I didnt find anything like this.
Let me know please. |
|
|
|
 |
Palbin

|
Posted:
Mon May 10, 2010 3:37 pm |
|
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...");
} |
|
|
|
 |
slackervaara
Worker


Joined: Aug 26, 2007
Posts: 236
|
Posted:
Mon Jun 14, 2010 12:54 am |
|
Which program do you recommend to make such substitions in multiple files in Linux?
I have been thinking about regexxer. |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Wed Jun 16, 2010 2:40 pm |
|
Is there any tool for windows? |
|
|
|
 |
slackervaara

|
Posted:
Thu Jun 17, 2010 12:40 am |
|
|
|
 |
gregexp
The Mouse Is Extension Of Arm

Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol
|
Posted:
Thu Jun 17, 2010 11:57 pm |
|
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. |
_________________ For those who stand shall NEVER fall and those who fall shall RISE once more!! |
|
 |
 |
hicuxunicorniobestbuildpc

|
Posted:
Fri Nov 05, 2010 7:19 pm |
|
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, |
|
|
|
 |
PHrEEkie
Subject Matter Expert

Joined: Feb 23, 2004
Posts: 358
|
Posted:
Fri Nov 05, 2010 11:06 pm |
|
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 |
_________________ PHP - Breaking your legacy scripts one build at a time. |
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sat Nov 06, 2010 7:59 am |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Sat Nov 06, 2010 4:33 pm |
|
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. |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sat Nov 06, 2010 6:09 pm |
|
it is already done. Thanks for warning me. I edited my last post. |
|
|
|
 |
djmaze
Subject Matter Expert

Joined: May 15, 2004
Posts: 727
Location: http://tinyurl.com/5z8dmv
|
Posted:
Sun Nov 07, 2010 12:07 pm |
|
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 |
It doesn't fix it, it only hides the issue  |
_________________ $ mount /dev/spoon /eat/fun auto,overclock 0 1
ERROR: there is no spoon
http://claimedavatar.net/ |
|
|
 |
Palbin

|
Posted:
Sun Nov 07, 2010 9:41 pm |
|
I would have to question if it is actually an issue in the first place  |
|
|
|
 |
|