stackuser10210
stackuser10210

Reputation: 352

PHP preg_replace URI's in phpBB

I'm trying to replace some image URI's in some phpBB forum post content retrieved from the DB for an external page.

preg_replace('/((https?|ftp).*\.(gif|png|jpg|jpeg))/i', '<img src="$1" alt "" />','http://somesite.com/image.png awordcontainingpng');

The above works well and as expected.

The thing is, when I try to apply the same to the MySQL result, nothing gets matched. Matches seem to work when I remove the escaped dot

E.g.:

preg_replace('/((https?|ftp).*(gif|png|jpg|jpeg))/i', '<img src="$1" />',$phpbb_post);  

But that's no good. The data is BLOB type - I don't know if that makes a difference. Could anyone help me with this?

Thanks.

Upvotes: 0

Views: 248

Answers (2)

entropid
entropid

Reputation: 6239

In PHPBB, when the images are saved into the database, they are totally encoded. This means that the dot . is replaced by a &#46;.

Upvotes: 2

Jaspreet Chahal
Jaspreet Chahal

Reputation: 2750

when you load Image directly from MYSQL you do it this way

so assuming you can retrieve image data follow it with this and save files as display.php

$sql = "SELECT * FROM `Images` WHERE `id` = $id"; // $id is what you pass from your img src
$image = mysql_fetch_object(mysql_query($sql));
header("Content-length: " . $image->size); // $image is your object
header("Content-type: " . $image->type); // say image/png
header("Content-Disposition: attachment; filename=" . $image->name);
echo $image->data;
die();

and from your HTML call this

<img src="display.php?id=YOUR_DB_REC_ID" />

Upvotes: 0

Related Questions