0

I am getting the following URL in my code (as a string) --

$image_url =""http:\\/\\/hello.us\\/kruger\\/web\\/invest\\/api\\/graph\\/gfx\\/tags\\/shop.png\""

However when i use this (in a facebook app) -- it says.. [$image_url] should represent a valid URL

What string operation (or something else) should i do to make the URL A valid image url? Thanks for your help.

1 Answer 1

1

There is error in the string "" at the start

""http:\\/\\/hello.us\\/kruger\\/web\\/invest\\/api\\/graph\\/gfx\\/tags\\/shop.png\""

I suppose the string is "\"http:\\/\\/hello.us\\/kruger\\/web\\/invest\\/api\\/graph\\/gfx\\/tags\\/shop.png\""

\\ in the string evaluates to \

Facebook api sees the url as this ""http:\/\/hello.us\/kruger\/web\/invest\/api\/graph\/gfx\/tags\/shop.png"" so it is unable to understand the url.

Replace the extra \ and " using the following code

url = data.replace(/([\\"])/g,'');

url returned is http://hello.us/kruger/web/invest/api/graph/tags/shop.png

var data ="\"http:\\/\\/hello.us\\/kruger\\/web\\/invest\\/api\\/graph\\/gfx\\/tags\\/shop.png\""; // YOUR CURRENT DATA

url=data.replace(/([\\"])/g,'');

console.log(url);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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.