I'm working with PHP and a JSON-based API that returns 2 fields with values for property photos:
- photo_url
- has_large
The photo_url is the regular sized photo URL.
Example: https://secure.example.org/Directory/AnotherDirectory/0008/102/12.jpg
If has_large = true, then we know a large photo exists, but the API doesn't return the specific URL.
However, from the API documentation, we know that if we prefix the image filename with a 'L', this gives us the correct large image URL:
Example: https://secure.example.org/Directory/AnotherDirectory/0008/102/L12.jpg
How can I programmatically prefix the filenames with the letter L, before writing them to the database (MySQL)?
Note: The URL structure is nearly the same for all photos.
The only parts of the image URLs that change for each property are:
- The 4th level directory which specifies property ID (In the example above -- 102)
- The filename itself, which is a maximum of 3 numbers (In the URL example above -- 12.jpg).
After hours of research on RegEx, preg_replace() and looking for similar solutions on StackOverflow, I'm still not sure how to accomplish this correctly using PHP.
Any help would be appreciated. Thanks in advance.