Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 26-01-2006, 12:19 PM   #11
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

Quick side-question... is it possible to make function in PHP of which an argument's not necessary? A function that'd be in the manual as function_name(int one, int two, [int three])
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 26-01-2006, 12:30 PM   #12
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

What are you trying to do?

Code:
Replace [b] with <b>?
If that's the case, then use ereg(i)_replace.
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 26-01-2006, 12:31 PM   #13
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

Or str_replace(), but it wouldn't make sure each [*b*]'d have a [/*b*], which's another thing that needs to be checked and fixed.
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 26-01-2006, 12:46 PM   #14
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

uhm
Code:
function blah($arg1, $arg2=10) {
can be called like:
blah(10)
and blah(10,20)
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 26-01-2006, 12:47 PM   #15
Rogue
10 GOSUB Abandonia
20 GOTO 10
 
Rogue's Avatar

 
Join Date: Nov 2004
Location: Afrim, Albania
Posts: 2,113
Default

Then in reg. expression, you have to check for this:

'(\[b\])?(\[\/b\])'

or something like that.

So, you're looking for regular expression that in one line has both opening and closing tag, and use replace function to fix it.

I'm not sure if ? will work for all characters between, data might be able to tell you that. (or just check reference on the page you posted above)

When you are done, check for tags that have no matching opening/closing tag.
Rogue is offline                         Send a private message to Rogue
Reply With Quote
Old 26-01-2006, 04:42 PM   #16
plix
Game freak

 
Join Date: Oct 2005
Location: ,
Posts: 113
Default

Quote:
Originally posted by Anubis@Jan 26 2006, 08:47 AM
Then in reg. expression, you have to check for this:
'(\[b\])?(\[\/b\])'
That wouldn't work as that statement doesn't require the opening bold tag to exist. A better (though not great) solution would be:
Code:
/\[b\](.*?)\[\/b\]/ig
which uses non-greedy matching (so you'd be best to use the perl regexp functions in PHP rather than the ereg functions).

If you're trying to write a forgiving BBCode parser and aren't just learning regexp then you're going about things all wrong. Regular expressions are for matching patterns, not for constructing push-down automata. Keep in mind that there's nesting and nesting requirements which regular expressions just can't handle well (it's possible with things like look-ahead and look-behind matching, but it's not pretty, it's not fast, and it's not reliable).
plix is offline                         Send a private message to plix
Reply With Quote
Old 26-01-2006, 06:41 PM   #17
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

How do you suggest I'd go 'bout it then?
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Old 26-01-2006, 06:46 PM   #18
Reup
10 GOSUB Abandonia
20 GOTO 10
 
Reup's Avatar

 
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
Default

Quote:
Originally posted by plix@Jan 26 2006, 07:42 PM
it's possible with things like look-ahead and look-behind matching, but it's not pretty, it's not fast, and it's not reliable
Not to mention a b*tch to debug...
Reup is offline                         Send a private message to Reup
Reply With Quote
Old 26-01-2006, 08:39 PM   #19
plix
Game freak

 
Join Date: Oct 2005
Location: ,
Posts: 113
Default

Quote:
Originally posted by Kon-Tiki+Jan 26 2006, 02:41 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (Kon-Tiki @ Jan 26 2006, 02:41 PM)</td></tr><tr><td id='QUOTE'> How do you suggest I'd go 'bout it then? [/b]

<!--QuoteBegin-plix

Regular expressions are for matching patterns, not for constructing push-down automata.[/quote]
Use a push-down automaton (a finite state machine doesn't include a stack, which is necessary to do open- and close-tag matching. It's a bit harder to implement if you haven't written one before, but it's not only easier to maintain, it's much more flexible.
plix is offline                         Send a private message to plix
Reply With Quote
Old 26-01-2006, 08:45 PM   #20
Kon-Tiki
[BANNED]

 
Join Date: Sep 2004
Location: Dentergem, Belgium
Posts: 1,811
Default

Hmmm... I've never heard of a push-down automaton. I'll see if I can find a tutorial 'bout it k:
Kon-Tiki is offline                         Send a private message to Kon-Tiki
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular sgtboat Blah, blah, blah... 4 26-11-2008 03:30 AM
When will regular updates start? Doink Blah, blah, blah... 6 13-12-2007 10:00 AM


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
Forum Jump
 


The current time is 06:01 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.