
June 21st, 2006
08:50 AM
Pawn Coder
Status: Offline!
Regex pattern help
What would the pattern be for something like this?
#QUOTE_POST_123#
Where "123" is the post's id, which I'll need to grab out of that it.
Thanks in advance!
---brandon
___________________
- Moderator at the official AMX Mod X forums

June 21st, 2006
09:55 AM
Nobody fucks with my title.
Status: Offline!
PCRE: #QUOTE_POST_(\d+)#
POSIX: #QUOTE_POST_([[:digit:]]+)#
Something like that.
___________________
<3

June 21st, 2006
04:46 PM
Pawn Coder
Status: Offline!
Hmm,
It's not recognizing the #'s. If I put QUOTE_POST_123 it still works.
Edit: Here's my current code:
if(preg_match('/^#QUOTE_TOPIC_([[:digit:]]+)#$/', $topic_body, $matches))
{
$found = $matches[1];
$topic_body = preg_replace('/^#QUOTE_TOPIC_([[:digit:]]+)#$/' , $forum->find_quotes_and_replace($found , TOPIC) , $topic_body);
$topic_body = preg_replace('/^#QUOTE_TOPIC_([[:digit:]]+)#$/' , '' , $topic_body);
}
With the /^ and $/ it's not recognizing it at all.
___________________
- Moderator at the official AMX Mod X forums
Last edited by v3x0rg, June 21st, 2006 04:51 PM (Edited 1 times)

June 21st, 2006
08:40 PM
Pawn Coder
Status: Offline!
Nevermind, I figured it out 
___________________
- Moderator at the official AMX Mod X forums

June 21st, 2006
09:02 PM
Neversidian
Status: Offline!
v3x0rg: Mind posting what you did so other future users who may come across this thread will know a solution? 

June 22nd, 2006
08:36 AM
<?php
/**
* A Valid pattern to match the digits of a string and ONLY the digits, if preg_match_all is used, the search will be repeated through the string.
*/
// '/([[:digit:]]+)/'
// Explanation
'/
( # Begin our sub patern
[ # Begin our character class
[:digit:] # We are only conerned about digits
] # End our character class
+ # add the + quantifier to match as many digits asneeded
) # End our sub pattern
/'
?>
Not tested but quality assured
just a explanation for other forum posters and im bored
___________________
I code alot.

June 22nd, 2006
10:39 AM
Neversidian
Status: Offline!
([0-9]+)
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

June 24th, 2006
04:11 AM
Pawn Coder
Status: Offline!
ringpull: Here's my code:
<?php
function find_quotes_in_post($id , $post_body , $type = NULL)
{
if($type != NULL)
{
$query = "SELECT * FROM forum_" . (($type == TOPIC) ? "topics" : "posts") . " WHERE id = '" . $id . "'";
$result = mysql_query($query) or die(mysql_error());
$str = "";
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_assoc($result);
$poster_id = $row["posterid"];
$body = $row["body"];
$stamp = $row["timestamp"];
$date = date("F j, Y, g:i a" , $stamp);
$str .= "<div class=\"quote\">";
$str .= "<img src=\"images/paper_folded2.gif\"> Posted by <b><a href=\"#\">" . name($poster_id) . "</a></b> - " . $date . "<br \><br \>";
$str .= $body;
$str .= "</div>";
}
$strings = array();
$replace = array();
preg_match_all('|#QUOTE_TOPIC_(\d+)#|', $post_body, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$strings[] = $match[0];
$replace[] = $str;
}
$post_body = str_replace($strings, $replace, $post_body);
unset($strings);
unset($replace);
$strings = array();
$replace = array();
preg_match_all('|#QUOTE_POST_(\d+)#|', $post_body, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$strings[] = $match[0];
$replace[] = $str;
}
$post_body = str_replace($strings, $replace, $post_body);
return $post_body;
}
}
}
?>
I sort of gave up on this idea though. If you want to suggest any changes to my code, please do so 
P.S. I don't think it works 100% though.
___________________
- Moderator at the official AMX Mod X forums

June 24th, 2006
09:50 AM
Nobody fucks with my title.
Status: Offline!
Originally posted by v3x0rg:
Hmm,
It's not recognizing the #'s. If I put QUOTE_POST_123 it still works.
Edit: Here's my current code:
if(preg_match('/^#QUOTE_TOPIC_([[:digit:]]+)#$/', $topic_body, $matches))
{
$found = $matches[1];
$topic_body = preg_replace('/^#QUOTE_TOPIC_([[:digit:]]+)#$/' , $forum->find_quotes_and_replace($found , TOPIC) , $topic_body);
$topic_body = preg_replace('/^#QUOTE_TOPIC_([[:digit:]]+)#$/' , '' , $topic_body);
}
With the /^ and $/ it's not recognizing it at all.
The ##'s were delimiters for the regex, I should have been more specific.
<?php
preg_replace('#^QUOTE_TOPIC_(\d+)$#', $forum->find_quotes_and_replace($found, TOPIC), $topic_body);
?>
preg == PCRE
ereg == POSIX
http://php.net/pcre
Read up, mate.
___________________
<3