I have a string, suppose $string which contains text to be converted through nl2br.
But, these text posts contain links to attachments, like [attachment=300] points to an attachment with id 300 (id is given through database).
What I want is, that if the string contains the phrase 
[attachment=*](let * be any number),
it first fetches the address of file from database and then replaces [attachment=*] to for example <img src="#">(where # is the address of the file with id *).
Can someone help?
 
    