MCrosbie Posted June 2, 2007 Share Posted June 2, 2007 Hi, Right, here is what I'm up to. In this CMS system all of the PHP code for the different variables e.g. {title} are stored in a MySQL database. The code searches for these variables in the pages contents, e.g. "<td>{title}</td>}", and replaces it with whatever the PHP code for that variable is e.g. $echo = $row['content']['title'], "<td>My Title</td>". In some of the pages, the variable is actually variable in it self, for instance for photo galleries, instead of creating a seperate variable for each gallery created, just use one. So for instance in a pages contents may be {PhotoGallery #100921}, this number needs to be named as $var['varivari'], before the PHP for variable is evaluated. I have already tried one solution using preg_match, which works fine, however on some pages where status=1, I get Internal Server Errors. Could you please help me to add in code to the "Current PHP code", to be able to enable this number to be picked up. Database: DM_content --------------------------------------------------------------------------------------------------------------------------------- | id | level | uplevel | title | description | keywords | content | author | template | --------------------------------------------------------------------------------------------------------------------------------- | 100920 | 0 | 0 | Page 1 | Description | page 1 page | My content| Michael | 100500 | --------------------------------------------------------------------------------------------------------------------------------- | 100921 | 1 | 100920 | Page 2 | Description | page 2, page | {title} | Michael | 100500 | --------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------ | status | membersonly | zorder | menu | ------------------------------------------------------------ | 0 | 1 | 0 | 1 | ------------------------------------------------------------ | 1 | 0 | 0 | 0 | ------------------------------------------------------------ Page 1 - Live to the public (status = 0), Members only page (membersonly = 1), Is not shown on the menu (menu = 1) Page 2 - Child page to Page 1, Under development (status = 1), Is shown in the menu (menu = 0) Database: DM_variables ------------------------------------------------------------------------------------------------------------------ | id | code | php | ------------------------------------------------------------------------------------------------------------------ | 300221 | /AO_photogallery #\b([1-9][0-9]{5})\b/ | $echo = PhotoGallery ... etc | ------------------------------------------------------------------------------------------------------------------ | 300222 | {title} | $echo = $row['content']['title'] | ------------------------------------------------------------------------------------------------------------------ Current PHP code: Code: include('includes/startup.php'); $res['chlock'] = mysql_query("Select * from DM_site where variable='HS_status'"); $row['chlock'] = mysql_fetch_array($res['chlock']); if($row['chlock']['value'] != 0 ){ include('includes/lockdown.php'); }else{ $res['contentselect'] = mysql_query("Select * from DM_content where level='1' and title LIKE '%home%'")or die("Error ". mysql_error().""); $row['contentselect'] = mysql_fetch_array($res['contentselect']); if(!$_GET['id']){$_GET['id'] = $row['contentselect']['id'];} $res['content'] = mysql_query("Select * from DM_content where id='".$_GET['id']."'")or die("Error ". mysql_error().""); $row['content'] = mysql_fetch_array($res['content']); $res['template'] = mysql_query("Select * from DM_templates where id='".$row['content']['template']."'")or die("Error ". mysql_error().""); $row['template'] = mysql_fetch_array($res['template']); $content = $row['template']['template']; $res['variables'] = mysql_query("Select * from DM_variables")or die("Error ". mysql_error().""); while($row['variables'] = mysql_fetch_array($res['variables'])){ $echo = ''; eval($row['variables']['php']); $content = str_replace($row['variables']['code'], $echo, $content); } echo $content; } PHP code that gets the number, but sometimes gives Internal Server Errors for unknown reasons Code: include('includes/startup.php'); $res['chlock'] = mysql_query("Select * from DM_site where variable='HS_status'"); $row['chlock'] = mysql_fetch_array($res['chlock']); if($row['chlock']['value'] != 0 ){ include('includes/lockdown.php'); }else{ $res['contentselect'] = mysql_query("Select * from DM_content where level='1' and title LIKE '%home%'")or die("Error ". mysql_error().""); $row['contentselect'] = mysql_fetch_array($res['contentselect']); if(!$_GET['id']){$_GET['id'] = $row['contentselect']['id'];} $res['content'] = mysql_query("Select * from DM_content where id='".$_GET['id']."'")or die("Error ". mysql_error().""); $row['content'] = mysql_fetch_array($res['content']); $res['template'] = mysql_query("Select * from DM_templates where id='".$row['content']['template']."'")or die("Error ". mysql_error().""); $row['template'] = mysql_fetch_array($res['template']); $content = $row['template']['template']; $res['variables'] = mysql_query("Select * from DM_variables ORDER by id ASC")or die("Error ". mysql_error().""); while($row['variables'] = mysql_fetch_array($res['variables'])){ $echo = ''; if(preg_match($row['variables']['code'],$content,$matches)){ $var['varivari'] = $matches[1]; if($matches[1] = "[1-9][0-9]{5}"){ $row['variables']['code'] = "{".$matches[0]."}"; } eval($row['variables']['php']); $content = str_replace($row['variables']['code'], $echo, $content); } } echo $content; Quote Link to comment https://forums.phpfreaks.com/topic/53943-getting-numbers-from-string-without-internal-errors/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.