discuz! X 3.0 bbcode and attach preg_replace
<pre><code>$tid = $_GET['tid'];
require_once $_SERVER['DOCUMENT_ROOT'] . '/common/class/class.thread.php';
$thread = new getThread;
$getThread = $thread-&gt;get_content($tid);
require_once $_SERVER['DOCUMENT_ROOT'] . '/common/class/class.thread.php';
$thread = new getThread;
$getThread = $thread-&gt;get_content($tid);
$attachmentTable = substr($tid, -1);
$tdatabase = new threadDatabase();
$tdatabase-&gt;query('SELECT * FROM mycms_forum_attachment_' . $attachmentTable .  ' WHERE tid = :tid ORDER BY aid DESC');
$tdatabase-&gt;bind(':tid', $tid);
$attachmentContainer = $tdatabase-&gt;resultset();
print_r($attachmentContainer);

//following is content , it pull from db($getThread)
//main content start
[attach]42[/attach]


[align=left][attach]53[/attach][/align]
content bla bla bla                      content bla bla bla
[align=left][attach]52[/attach][/align]
content bla bla bla


content bla bla bla
//main content end

//following is attachment file
[0] =&gt; Array ( [aid] =&gt; 53 [tid] =&gt; 32 [pid] =&gt; 32 [uid] =&gt; 1 [filesize] =&gt; 152633 [attachment] =&gt; 201305/22/142619h42az34077hhra0p.jpg [width] =&gt; 1080 ) 
[1] =&gt; Array ( [aid] =&gt; 52 [tid] =&gt; 32 [pid] =&gt; 32 [uid] =&gt; 1 [filesize] =&gt; 89015 [attachment] =&gt; 201305/22/142618wx3njhgf3n883zxr.jpg [width] =&gt; 1080 ) 
</code></pre>

<p>how do i use preg_replace to change the [attach]53[/attach] to be </p>

<p>the src take from the array where aid=53 due to it is [attach]53[/attach] and width too</p>

<p>i had try the following , but get error and i know is wrong to do in this way , because $attachmentContainer[$1]['attachment'] is start with 0 and 53 is not exist , get stucked and no idea to do.</p>

<pre><code>$threadContainer = preg_replace('/\[attach\](.*?)\[\/attach\]/i', '&lt;img src="' . $attachmentContainer[$1]['attachment'] . '" width="' . $attachment[$1]['width'] . '" /&gt;', $getThread['message']);
</code></pre>

<p>my question:
do it in javascript or php better?
how do i preg_replace all the [attach][/attach] with correct src and width store at db ?
and check the content , how do i handle these "space" to <br/> for line break?</p>

<p>i'm trying to pull discuz! x3.0 thread content directly from db.</p>

<p>THANKS for teaching!</p>
