Dear Friends,
Thanks for all your feedback. I am grateful for the attempts, but the problem is the exact way around. You all seem to try to match the number IN the url. Whereas, in my case, I already KNOW the number, and I want to properly construct the URL to fetch the image for that ISBN.
This is what I am trying to achieve:
I have built a few small websites that sell books. The book databases that feed these websites are coming from regular POS systems, and therefore contain product information such as titles, barcodes, isbn numbers (most of them) and price info. However, that is not sufficient for presentation on a website. While the website owners will be able to add text descriptions and other info, it takes a long time to scan images or hunt them down on the web and add them to the website.
So, I decided to give them a hand and I have done some research and have come up with about 60 different book-selling websites that save/construct urls for their images involving the ISBN of the book.
Currently I have a programmatic solution, in which I have these pre-defined urls with their substitution rules (str_replace and substring), like so:
$urls[] = array("http://ec2.images-amazon.com/images/P/".$against.".02._SS500_SCLZZZZZZZ_V58694805_.jpg", "AmazonEC2");
$urls[] = array("http://www.cokesbury.com/products/5.0/".$against.".jpg", "Cokesbury");
$urls[] = array("http://www.inspire4less.com//productimages/".substr($against, 0, 2)."/".$against.".JPG", "Inspire4Less");
$urls[] = array("http://www.bookfinder4u.com/noindex/show_images_isbnsearch.aspx?size=l&isbn={$against}", "BookFinder4U");
$urls[] = array("http://img.textbookx.com/images/large/".substr($against, -2, 2)."/".$against.".jpg", "TextBookX");
So, I have about 60 elements that get added to the $urls array, all with their respective rules and substring replacements. $against is my query (isbn) number.
In my program, when I want to find the cover of a book, I run this method and pass the ISBN of the particular book as parameter. Then, I loop through the elements of the array, and for each iteration, I replace that $against in the url with the actual ISBN (or fragments of it). Then I try that url to see if the image does exist and fetch it.
Now, this works perfectly programmatically, but I would like to move those urls (before construction) IN the database, so that I can easily add new ones, edit them and so on.
While this is very simple for urls that only contain the WHOLE ISBN in the replacement, I do not know how to do it for urls that must also manipulate that isbn and use only two characters or one character and so on.
So, while it is easy, in the database, so put the following:
http://www.bookfinder4u.com/noindex/show_images_isbnsearch.aspx?size=l&isbn={$against}
in some form like this:
http://www.bookfinder4u.com/noindex/show_images_isbnsearch.aspx?size=l&isbn=[ISBN]
and at runtime replace [ISBN] with the actual number I am searching for,
I do not know how to also construct a substituteable variant for the PHP substring equivalents:, such as this one:
http://img.textbookx.com/images/large/".substr($against, -2, 2)."/".$against.".jpg
Here, the ISBN is used in its entirety, but also, a substring of it, namely the last two characters, so two replacements must be done, one with the whole isbn and one with a fragment.
I do not know how to construct a rule for these (I suppose something very similar to the substr function AND further more how to write a regex to replace these at run time, so that all I would have to do when I need to add a new url for parsing or edit one, I would not have to edit the source-code of my program.
For example I am thinking I could do this, in the DB:
http://img.textbookx.com/images/large/[substr($against, -2, 2)]/[$against].jpg
and at runtime, use the regex to match and replace [substr($against,-2,2)] with the last characters and [$against] with the entire number. There can be more variants, so there must be a standard way, so that while I maintain the same "syntax", the regex would match the correct characters.
I hope this clarifies things. Hope I did not confuse even more.
[EDIT]: I guess now that I think of it, and as has been mentioned, maybe this is not even possible without extra programmatic manipulation. Maybe there can be a way to bring it closer. But I think as it stands right now, I guess my question really is: how to construct a substr(STRING, Start, CharNum) function equivalent AND the appropriate rules for it. My examples above include something like [$against] and [substr($against, 1, 1)] but I don't necessarily have to use the [ and ] characters. Any way this can be made so that it works, would help. The PHP substr function is explained here:
http://www.php.net/substr
and the str_replace, here:
http://www.php.net/str_replace
Note that substr uses - (minus) to denote characters starting at the end of the string, and this must be supported since some of my examples use this also.