I’ve created an API for use on my website.
The API I made strips everything using mysql_real_escape_string then puts it into the database.
But the problem I’m having is the URL that my php scripts are using to access the API is cut short sometimes…
Which I have narrowed down to one of the parameters…
When its Ford Mondeo 22′ the URL that is passed to simplexml_load_file is
http://mydomain.com/api/create.xml?api_number=brho15p6z1dhqwf5tsff&env=live&number=AJ20023232&title=Ford Mondeo 22’&image=http://mydomain.com/wp-content/uploads/2012/10/914955-150×150.jpg
but the API reports back the URL accessed as
If I remove the single quote then everything works fine, any idea how to correct this I suspect there’s something I’ve overlooked when passing variables in the URL
It is the spaces in the “Ford Mondeo 22′” value that is causing the problem. You cannot have a spaces in the URL. You need to use escape characters. The encoded version of the parameter should be
Ford%20Mondeo%2022′
%20 is the escape character for space
I.e. the whole URL should read as follows:
EDIT:
Your comment indicates that you use PHP. In PHP, you can use urlencode($foo) and urldecode($foo) to switch between the normal string and the encoding string.