Welcome to WebmasterWorld Guest from 54.146.201.80

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)

Full Member

10+ Year Member

joined:Mar 7, 2003
posts: 301
votes: 0


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;
$m_id++;
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 July 7, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:June 18, 2008
posts:85
votes: 0


why don't you use replace?

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

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

Full Member

10+ Year Member

joined:Mar 7, 2003
posts: 301
votes: 0


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 July 7, 2008 (gmt 0)

Senior Member

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

joined:Nov 12, 2005
posts:5966
votes: 0


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 July 7, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Mar 7, 2003
posts:301
votes: 0


Thanks that seems to be working :)