Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

extract variables from content

content variables extract



1:46 am on Jul 7, 2008 (gmt 0)

10+ Year Member

I'm trying to hack the following code.
What it does is extract the first digit (1) from [hidepost=1]content[/hidepost]
What i want to do is use code like [hidepost=Level1]
so I need to extract everything between the "[hidepost=" and "]"

Any ideas? Thanks!

global $current_user, $user_ID, $hidepost_content_text,$user_level, $m_id, $hidepost_role_text;
preg_match_all('#\[hidepost(.*?)\](.*?)\[/hidepost\]#sie', $content, $matches);//Find the hidepost tag
$level_tag = $matches[1][$m_id];

$max_level = 0;
if ($level_tag[0] == '=') {
$max_level = $level_tag[1]; //Get the level require
//Get the level require


2:10 am on Jul 7, 2008 (gmt 0)

5+ Year Member

why don't you use replace?

$hidepost = eregi_replace("hidepost=", "hidepost=level", $hidepost);


2:52 am on Jul 7, 2008 (gmt 0)

10+ Year Member

Hi Dull,

I'm not trying to replace the contents, I'm trying to extract the contents from the string. But maybe I'm misunderstanding the operator?

[edited by: David_M at 3:06 am (utc) on July 7, 2008]


3:06 am on Jul 7, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Try something like this:

$pattern = '/\[hidepost=([^\]]+)\]/i';
if(preg_match($pattern, $string, $match)) {
echo '<pre>'; print_r($match); echo '<pre>';
} else {
echo 'No match!';


4:18 am on Jul 7, 2008 (gmt 0)

10+ Year Member

Thanks that seems to be working :)

Featured Threads

Hot Threads This Week

Hot Threads This Month