Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2003, 07:34 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
parsing [php] tags

ok, i am tuning up the tutorial viewer now and recreating the parsing that vbulletin does. it's not as easy as just copying over the functions unfortunately because there is so much other stuff happening in vbulletin.

i need to get the text in between the [ p h p ] and [ / p h p ] tags into a variable and i am set. it needs to look for one set of tags at a time in case there are multiple php tags in a post.

PHP Code:
<?
$post
="here is some code [ph p]$i=1;[/ ph p]";
?>
how can i parse $post and get '$i=1;' into its own variable?
sde is offline   Reply With Quote
Old 03-03-2003, 08:10 PM   #2 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
well, the regexp to match inside php tags would be:

Code:
 ".*?\[php\](.*?)\[/php\].*?"
note that given "[ph p]abc[/ph p]xxx[ph p]123[/ph p]" you would get my wonderful name; "abc123".

note that "\" is escaping the "[" and "]" so if "\" is an escape in php ( which it probably is ) you'll need to escape that first. but does php even use quotes for regexps? i can't remember.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-03-2003, 08:16 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
thanks, .. yes php uses quotes for regex .. there is a problem with that though because i don't want my variable to equal 'abc123' it needs to parse each set of tags individually .. hrrm . i made a bbs a while back and i thought i figured this one out, but i forgot how .. i'll keep trying to re-invent the wheel

thanks for the help =)
sde is offline   Reply With Quote
Old 03-03-2003, 08:18 PM   #4 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
Quote:
Originally posted by sde
thanks, .. yes php uses quotes for regex .. there is a problem with that though because i don't want my variable to equal 'abc123' it needs to parse each set of tags individually .. hrrm . i made a bbs a while back and i thought i figured this one out, but i forgot how .. i'll keep trying to re-invent the wheel

thanks for the help =)
then split the input based on [/php] and work on that basis, i forget what perl regexps look like so i can't really remember the grouping but i think you'll find that way ( splitting based on end tag ) is easier then dealing with possibly unlimited amount of tags.
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 03-04-2003, 11:04 AM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
i would do this using php's explode() and split() functions.
joe_bruin is offline   Reply With Quote
Old 03-04-2003, 12:59 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
well i got it working now. my original idea was to use the exact vbulletin parsing function so the code would highlight just as it does in a vb post.

the problem was that i was running the script outside of the /forum directory so the includes were messing things up.

after a lot of troubleshooting and some help from another, .. i found a pretty cool function that is so simple, but made it work.

the idea here is that i needed to include a file called 'global.php' from the /forum directory. global.php had many includes in it which were reletive to the forum directory.. so naturally if i included that file on a level below /forum , the paths would not match when executed.

here is the solutions:
PHP Code:
<?
// change directory to the forum directory
chdir("forum/");

// execute global.php inside its own directory
include("./global.php");

// change the current directory back to where the current script running is
chdir("./");
?>
i learn something everyday.
sde is offline   Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tips on writing your tags & keywords! SiteTutor PHP 11 06-12-2002 08:31 AM


All times are GMT -8. The time now is 05:11 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting