-3

My database contains links to images which are displayed properly within their structure. When I run my PHP code, the outputted JSON values are the same image links which fail to load because the links keep being outputted like this:

https:\/\/i.ebayimg.com\/00\/s\/NDQwWDgwMA==\/z\/ViAAAOSwhmtbN7fe\/$_59.JPG\r\n

Even though the database displays it like this:

https://i.ebayimg.com/00/s/NDQwWDgwMA==/z/ViAAAOSwhmtbN7fe/$_59.JPG

Is there something wrong with my PHP code?

Andreas
  • 23,610
  • 6
  • 30
  • 62
CheeseFerrari
  • 57
  • 1
  • 7
  • 1
    In PHP `\\` is "escape". Meaning don't read `\\` as a special character, just read it as a string `\\` with no actions attached. Edit: see it's even impossible to write it here on SO. That's how special that character is – Andreas Jul 04 '18 at 18:28
  • i see no json here ... how about showing some code no ? – YvesLeBorg Jul 04 '18 at 18:35

2 Answers2

0

you can use string replace function in php for remove (\)

$your_string = str_replace("\\", "", $your_string);
Courses Cart
  • 46
  • 1
  • 9
0

Simple use stripslashes()

First remove \r\n using str_replace() from link/url and then apply stripslashes()

$link = 'https:\/\/i.ebayimg.com\/00\/s\/NDQwWDgwMA==\/z\/ViAAAOSwhmtbN7fe\/$_59.JPG\r\n';
$link = stripslashes( str_replace("\\r\\n", '', $link) );
echo $link;
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50