I have an array element that contains a subpage's content: $page['content']
I want to do some MySQL query, if the variable's content contains this pattern: {gallery:somerandomIDnumber}
The problem is, I don't want to lose the other stuff, and it's also important that the query should run where the pattern belongs.
For example, this is the $page['content'] content:
<h1>Title of the page</h1>
{gallery:10}
<p>Other informations...</p>
I tried this with preg_match function, but unfortunately I can't figure it out, how I can save the other content around my {gallery:10} pattern.
// Gallery include by ID
preg_match('~\{gallery\:[0-9]{1,5}\}~', $page['content'], $matches);
foreach($matches[0] as $value) {
$int = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
$query = 'SELECT * ';
$query .= 'FROM gallery_images ';
$query .= 'WHERE gid = '.$int;
$gallery = ms_query($query); //ms_query is a function I wrote myself. Unlike mysqli_query function this function doesn't require the connection parameter every single time I call it, only the query itself
while($gimage = mysqli_fetch_assoc($gallery)) {
echo '<img src="admin/uploaded/'.$gimage['imagepath'].'" width ="100">';
}
}
Summarazing, in this situation, I want to echo
1. the title of the page
2. some imagepath from my database
3. other informations
Thanks in return for Your help!