BlameThePixel!

BTForum » BlameTheOffTopic Forums » BlameTheGeneralOffTopic » Two REGEXP questions

[]Dingbats
;
Send PM
An Avatar
Posts: 1970
Threads: 50
Mood: Optative
Money: £268.57 (D)
(+ Friend)
Not online within the last half an hour
I have two questions about regular expressions in PHP.

#1:
What would the REGEXP for checking for [quote=someone]? I can do the replacing myself.

#2:
What would the REGEXP for checking for URLs and replacing them be? Here I need the replacing part too.

Any help would be very appreciated. :)
03.10.04 18:22
Post #1
[Softbrain Games] [Hide Sig (2)] [Profile] [Quote]
[UA]tundraH
Statusless
Send PM
Posts: 566
Threads: 20
Money: £1.26 (D)
(+ Friend)
Not online within the last half an hour
The easiest way would be to download phpBB and look at includes/bbcode.php.
03.10.04 22:02
Post #2
[tundraH.com] [Hide Sig (0)] [Profile] [Quote]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
\n
<?PHP\n

    
//[quote]
    
$findq "/[quote](.+?)[/quote]/si";
   
$replq "<br><div class=quote><font size=1 color=#888888><b>Quote:</b></font><br>$1</div>";
   //[quote=name] why was a dot not allowed in the name??
    
$findqn = "/[quote=(.+?)](.+?)[/quote]/si";
    
$replqn "<br><div class=quote><font size=1 color=#888888><b>Quoted :: $1</b></font><br>$2</div>";

  
//quotes must be done recursively
  
while (preg_match($findq,$str)) {
    
$str = preg_replace($findq,$replq,$str);
  }
  while (
preg_match($findqn,$str)) {
   
$str preg_replace($findqn,$replqn,$str);
  }
\
n?>
\n
04.10.04 02:07
Post #3
Last edited: 04.10.04 02:08 (CBWhiz - 1 times) [Hide Sig (3)] [Profile] [Quote]
[S]ReadMe
Absent
Send PM
Posts: 2820
Threads: 85
Money: £43.42 (D)
(+ Friend)
Not online within the last half an hour
of course you'll need to escape the [s since they are reserved for character classes.

I'd also export much neater code if i were you, throw in some line breaks, indentation and valid markup =p

________________
Cant be arsed to remake my sig.
05.10.04 16:46
Post #4
[Hide Sig (7)] [Profile] [Quote]
[S]CBWhiz
Looking For Status
Send PM
Posts: 1044
Threads: 130
Money: £1343.20 (D)
(+ Friend)
Not online within the last half an hour
Now that I think about that, thats true :)

COncidering i copieed and pasted form this forum's code, not sure why its working right tnow :D
06.10.04 04:03
Post #5
[Hide Sig (3)] [Profile] [Quote]
[]Dingbats
;
Send PM
An Avatar
Posts: 1970
Threads: 50
Mood: Optative
Money: £268.57 (D)
(+ Friend)
Not online within the last half an hour
It doesn't work, and adding the escape characters doesn't do any difference! I get the errors "Warning: Unknown modifier 'q' in c:\program\easyphp\www\sbg\functions.php on line 138" and "Warning: Unknown modifier 'q' in c:\program\easyphp\www\sbg\functions.php on line 142" for every post in the thread.
Those lines are the lines where the two whiles start.
Quotes just show up as [ quote=someone ]something[ /quote ]. The same goes for [quote]-style quotes.
06.10.04 14:36
Post #6
Last edited: 06.10.04 18:16 (Dingbats - 1 times) [Softbrain Games] [Hide Sig (2)] [Profile] [Quote]
[S]ReadMe
Absent
Send PM
Posts: 2820
Threads: 85
Money: £43.42 (D)
(+ Friend)
Not online within the last half an hour
can i see exactly what regex you've used?

________________
Cant be arsed to remake my sig.
06.10.04 17:03
Post #7
[Hide Sig (7)] [Profile] [Quote]
[]Dingbats
;
Send PM
An Avatar
Posts: 1970
Threads: 50
Mood: Optative
Money: £268.57 (D)
(+ Friend)
Not online within the last half an hour
\n
<?PHP\n
$find 
"/[quote](.+?)[/quote]/si"
$repl "<br><div class='quote'><font size='1' color='#888888'><b>Quote:</b></font><br>$1</div>"
$findn = "/[quote=(.+?)](.+?)[/quote]/si"
$repln "<br><div class='quote'><font size='1' color='#888888'><b>Quote :: $1</b></font><br>$2</div>"

//Quotes must be done recursively 
while(preg_match($find$string)) 
{
    
$string = preg_replace($find$repl$string); 
}
while(
preg_match($findn$string)) <br />
{
    
$string preg_replace($findn$repln$string);
}

return $string;\n?>
\n
06.10.04 18:17
Post #8
Last edited: 06.10.04 18:19 (Dingbats - 2 times) [Softbrain Games] [Hide Sig (2)] [Profile] [Quote]
[S]ReadMe
Absent
Send PM
Posts: 2820
Threads: 85
Money: £43.42 (D)
(+ Friend)
Not online within the last half an hour
\n
<?PHP\n
$find 
"/[quote](.+?)[/quote]/si"
$repl "<br><div class='quote'><font size='1' color='#888888'><b>Quote:</b></font><br>$1</div>"
$findn = "/<br><div class='quote'><span class='quoteheader'>Quoted :: (.+?)</span><br>(.+?)[/quote]/si"
$repln "<br><div class='quote'><font size='1' color='#888888'><b>Quote :: $1</b></font><br>$2</div>"

//Quotes must be done recursively 
while(preg_match($find$string)) 
{
    
$string = preg_replace($find$repl$string); 
}
while(
preg_match($findn$string)) <br />
{
    
$string preg_replace($findn$repln$string);
}

return $string;\n?>
\n

you needed to escape the / in
since you were using / as your delimiter. I always use ' cos it's neater and less likely to appear in a pattern, ie:
"'(.+?)'si"
________________
Cant be arsed to remake my sig.
06.10.04 18:36
Post #9
[Hide Sig (7)] [Profile] [Quote]
[]Dingbats
;
Send PM
An Avatar
Posts: 1970
Threads: 50
Mood: Optative
Money: £268.57 (D)
(+ Friend)
Not online within the last half an hour
I'll try that.
Edit: It works! Thank you! :)
07.10.04 05:46
Post #10
Last edited: 07.10.04 13:36 (Dingbats - 1 times) [Softbrain Games] [Hide Sig (2)] [Profile] [Quote]

Post Reply

Jump To:


Your Comments:

Donate to BlameThePixel:
Donate to BTP Via PayPal


[22 Queries, Page Loaded in 1.092012 Seconds]

ShoutMeUp

Xmas Greetings from waka waka waka waka []Unvalidated EmailChristmasRiddle MERRY CHRISTMAS EVERYONE! []Spleet Except for Spleet. []TheAbdBoy Always bummin' a brother out. []Spleet Happy New Year everyone! But Spleet. []TheAbdBoy

Word Association

All

-10 Ago-

MiddleEastern []AlphaWolf camel [S]Bloopy toe []TheAbdBoy moose knuckle [S]Bloopy MeatLoaf []Spleet IdDoAnything4Lo ve []AlphaWolf rub n tug []TheAbdBoy tugboat []The Pope rope [S]Bloopy race []TheAbdBoy

-Latest-


Must be logged in to add new words

FictoLeague

You have to be logged in to vote...

Member Stats

Date: 18.12.24.
Members: 4731.
Latest: []Unvalidated Emailsdsakldsaldklasdsdsa
Active:
0 user(s)
1 guest(s)

On chat:
Lots of people

Files: 3330

Bloopy's Site
Get Firefox Get Opera Donate to BTP Via PayPal