Php and regular expressions
Okay kinda stumped here i have a php file that has code like:
if($this->user->inRole('marketing')){ $html .= " <tr>"; $html .= " <td><a href='#' onClick='show(\"marketing\")' class='normal'>::Marketing</a>"; $html .= " <div id='marketing' style='display:none;'>"; $html .= " <table cellspacing='0' border='0' width='150' cellpadding='0'>"; if($this->user->inRole('marketing_projects')){ $html .= " <tr>"; $html .= " <td> <a href='?content=marketing&process=projects' class='subnormal'>::Projects</a></td>"; $html .= " </tr>"; } if($this->user->inRole('marketing_developers')){ $html .= " <tr>"; $html .= " <td> <a href='?content=marketing&process=developers' class='subnormal'>::Developers</td>"; $html .= " </tr>"; } if($this->user->inRole('marketing_handsets')){ $html .= " <tr>"; $html .= " <td> <a href='?content=marketing&process=handsets' class='subnormal'>::Handsets</td>"; $html .= " </tr>"; } if($this->user->inRole('marketing_carriers')){ $html .= " <tr>"; $html .= " <td> <a href='?content=marketing&process=carriers' class='subnormal'>::Carriers</td>"; $html .= " </tr>"; } $html .= " </table>"; $html .= " </div>"; $html .= " </td>"; $html .= " </tr>"; } i need to write a parser that will open the php file and find the inRoles. Pretty much it would need to open it find each inRole('name') and copy the name into a file so i would end up with marketing marketing_projects marketing_developers marketing_handsets marketing_carriers in another text file im just not sure how to set up the regular expressions to do this or which reg-ex function to use |
PHP Code:
|
Warning: ereg_replace(): REG_EPAREN: in c:\inetpub\wwwroot\mobile_production\version 0.2\roles.php on line 8
Warning: ereg_replace(): REG_EPAREN:eparentheses not balanced in c:\inetpub\wwwroot\mobile_production\version 0.2\roles.php on line 8 i get those two errors when i run the script |
add a \ in
PHP Code:
|
OK keefaz,
Lets make life a little harder for you....;) What if there are 500 files like the one in first post. What do we do to read all files in the same directory and output the result? Is it possible? Surprise me! |
yeah it is possible ;)
Assuming directory contains just your php file to parse, PHP Code:
|
Super cool. Care to explain What this line means?
$str = ereg_replace( "^(.*)\('", "", $lines[$i] ); Let me guess. In english it would be Get rid of anything before (' Right? |
Yes you guess it right.
^: search from the beginning of line . : any character match * : search previous 0 times or more |
Just look up regular expressions cuz man are the fun and so useful
|
They have 'Hooked on Phonics' program that is as hot as the Reality TV, so why don't we have 'Hooked on ReGex'? ;)
|
All times are GMT -5. The time now is 07:42 PM. |