Shekhar Chatterjee Shekhar Chatterjee - 4 months ago 11
MySQL Question

Repair double slash in Image Url

Whenever I try fetching Image Url from database, all single slash convert into double slash while viewing in browser. Here I have listed both correct URL and displayed URL.

Correct URL:

https://lh4.googleusercontent.com/-wXQNp0wmIQM/AAAAAAAAAAI/AAAAAAAAAaM/tXe1ViOOrA0/s96-c/photo.jpg


Displayed URL:
https:\/\/lh4.googleusercontent.com\/-wXQNp0wmIQM\/AAAAAAAAAAI\/AAAAAAAAAaM\/tXe1ViOOrA0\/s96-c\/photo.jpg


Although I know how to use PREG MATCH to rectify this issue, however I am fetching the complete row from MySQL and converting it into JSON.

Answer

You could use stripslashes($str) within your loop to remove the backslashes. For example, if your code is looping through some data and the image URL is $data['imageURL']; you could do something like this:

    <?php
        while($your_db_loop_still_has_rows){
            $imageURL = stripslashes($data['imageURL']);
            // DO WHATEVER YOU LIKE WITH THE $imageURL    
        }

Hope this helps a bit....

Cheers & Good-Luck...

Comments