homepage Welcome to WebmasterWorld Guest from 54.205.106.111
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
extract variables from content
content variables extract
David_M




msg:3691845
 1:46 am on Jul 7, 2008 (gmt 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
}

 

dulldull




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

why don't you use replace?

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

David_M




msg:3691869
 2:52 am on Jul 7, 2008 (gmt 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]

eelixduppy




msg:3691872
 3:06 am on Jul 7, 2008 (gmt 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!';
}

David_M




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

Thanks that seems to be working :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved