1

So I'm currently creating a project and in this project it requires a user to add information about their server/game.

I'm making the information field a little unique by adding some BB codes, and so far I've added nearly all but I need one small help.

I want add to add

[img w=100 h=100]IMG link here[/img]

the "100" means the amount, that was just a random number. Here is my PHP code that used:

preg_replace('/\[img w=(.*?) h=(.*?)](.*?)\[\/img\]/i', '<img src="$3" height="$2" width="$1" draggable="false" />', $str); '

but the code returns this: <img src="IMG LINK" height="100 h=100" draggable="false" />

if anyone could help me I'd appreciate it, thank you.

0

1 Answer 1

2

Your code works correctly (PHP 5.2.8):

$str = "[img w=100 h=200]IMG link here[/img]";

echo preg_replace('/\[img w=(.*?) h=(.*?)](.*?)\[\/img\]/i', '<img src="$3"     height="$2" width="$1" draggable="false" />', $str);

Outputs

<img src="IMG link here" height="200" width="100" draggable="false" />

If you are getting different results, share your PHP version and example similar to mine above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.