Benjamin Mitchell
Benjamin Mitchell

Reputation: 29

How to replace a portion of a dynamic php string

I have a page that is calling dynamic URL content from MySQL via Primary ID. The information is being called and echoed as

"../images/icons/filename.jpg"

via this command:

<php echo $row_getimages['icon']; ?>

I want to change "../images/icons/filename.jpg" to:

"http://www.mysite.com/images/icons/filename.jpg"

Does anyone know if this is possible with a str_replace or some other command? I have tried that particular one but I am having trouble figuring out the proper syntax.

Upvotes: 0

Views: 172

Answers (2)

Ibu
Ibu

Reputation: 43820

Yes you can user str_replace():

<?php echo str_replace("../","http://www.mysite.com/",$row_getimages['icon']); ?>

Just make sure you have the parameters in the correct order:

Upvotes: 0

GBD
GBD

Reputation: 15981

Try

<?php echo str_replace('../','http://www.mysite.com/',$row_getimages['icon']); ?>

Upvotes: 1

Related Questions