Current location: Hot Scripts Forums » Programming Languages » PHP » pls help learner understand following:


pls help learner understand following:

Reply
  #1 (permalink)  
Old 03-13-06, 07:18 PM
clantron clantron is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
pls help learner understand following:

PHP Code:

function openpage(){

        return 
"<a href='http://www.google.com' target='_blank' onClick=\"".popup("http://www.google.com").";return false;\">test</a>";
}
function 
popup($page){
        return 
"window.open('$page','".preg_replace("([^[:alnum:]])","",$page)."','scrollbars=no,resizable=no,width=300,height=300')";

Now I understand most of this.
But what exactly does preg_replace replace here?
I know a nice rule, if it aint broken dont fix it, but I'm just wondering what it does? So I can understand what is going on.

Used google in testing so I could see if it worked and it does to my suprise.
again .. following part is where I'm lost:
return "window.open('$page','".preg_replace("([^[:alnum:]])","",$page)."','scrollbars=no,resizable=no,width=300,height=300' )";

Also, everything works there is no bug. I'm just hungry for knowledge
__________________
"I don't know the key to success, but the key to failure is to try to please everyone."
Reply With Quote
  #2 (permalink)  
Old 03-13-06, 10:44 PM
nekeno12 nekeno12 is offline
Wannabe Coder
 
Join Date: May 2004
Location: CO
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
This particular regex replaces any characters NOT equal to '[:alnum:]'. Don't ask me why the regex is looking for that particular string, but there's your answer.
Reply With Quote
  #3 (permalink)  
Old 03-14-06, 09:47 AM
clantron clantron is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
hmm again this regex thing..
came across it about 5 min ago in another thing.
*starts googling and php manual-ing*

Thanks for the explanation
__________________
"I don't know the key to success, but the key to failure is to try to please everyone."
Reply With Quote
  #4 (permalink)  
Old 03-14-06, 12:53 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Here's a quick RegExp tutorial.

Modifiers
i case-insensitive pattern matching.
g global replace, or replace all
m Treat string as multiple lines. That is, change ``^'' and ``$'' from matching at only the very start or end of the string to the start or end of any line anywhere within the string
s Treat string as single line. That is, change ``.'' to match any character whatsoever, even a newline, which it normally would not match.
x Extend your pattern's legibility by permitting whitespace and comments.

Special Characters
The following should be escaped if you are trying to match that character

\ ^ . $ | ( ) [ ]
* + ? { } ,

Special Character Definitions
\ Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
More Special Character Stuff
\t tab (HT, TAB)
\n newline (LF, NL)
\r return (CR)
\f form feed (FF)
\a alarm (bell) (BEL)
\e escape (think troff) (ESC)
\033 octal char (think of a PDP-11)
\x1B hex char
\c[ control char
\l lowercase next char (think vi)
\u uppercase next char (think vi)
\L lowercase till \E (think vi)
\U uppercase till \E (think vi)
\E end case modification (think vi)
\Q quote (disable) pattern metacharacters till \E
Even More Special Characters
\w Match a "word" character (alphanumeric plus "_")
\W Match a non-word character
\s Match a whitespace character
\S Match a non-whitespace character
\d Match a digit character
\D Match a non-digit character
\b Match a word boundary
\B Match a non-(word boundary)
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
\G Match only where previous m//g left off (works only with /g)
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #5 (permalink)  
Old 03-14-06, 01:28 PM
clantron clantron is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
thx man
copied it into a txt file for future reference
__________________
"I don't know the key to success, but the key to failure is to try to please everyone."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php popup window code help, pls! usmaster81 PHP 5 04-29-05 04:09 PM
pls HELP VB 5.0 colour change K Z Visual Basic 1 12-10-04 02:19 AM
pls critique www.myfijifriends.com roi Website Reviews 10 07-03-04 05:04 AM
Help Installing A Script Pls dangol PHP 1 04-30-04 08:35 PM


All times are GMT -5. The time now is 06:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.