| 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 :)
|
|
|