Jump to content

Functions inside str_replace


Porl123

Recommended Posts

I have a bbcode function with this in it:

 

<?php
$string = str_replace("[img]http://","<img src=\"", $string);
$string = str_replace("[[b][/b]/img]","\" />", $string);
?>

 

and I've trying to have it so when somebody uses the [/img] there's my image link checking function inside. So something like <img src="".check_image($link)."" /> if it was straight forward, but I'm not sure how I'd do that if the image tags were separate like mine

 

If you know how I'd get around this it'd be much appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/125766-functions-inside-str_replace/
Share on other sites

The problem you have with your code at the minute appears to be closing the img tag. From what i can see you'll write out the

<img src="myimage.jpg

bit, but you're not closing the tag.

 

You need to get the end position to close the tag. Also with regards to calling a function, something like

$string = str_replace("[img]","<img src=\"", check_image($link) );
$string = str_replace("[/img]", "/>", $string);

 

Or something along those lines...

 

the problem here is that we can't see what variables $link, $string, etc start off as, thus rendering our solution rather m00t until we see more code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.