Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

PHP Substring Equivalent in Regex

  •  12-02-2007, 3:09 PM

    PHP Substring Equivalent in Regex

    Hello, I am building some custom urls for finding images online. These are like:

     www.website.com/images/123456789.jpg

     Usually these are isbns or upc codes for products or books.

    I am currently doing string replacement by php, for substituting the number by an expression and replacing that expression with whatver number, when I do a search.

    For example

    www.website.com/images/{REPLACEMENT}.jpg

     and then I replace this with the actual product number.

    This works fine but some sites store the numbers as such:

    www.website.com/images/978/9789731234.jpg

    or

    www.website.com/images/1/2/3/123456789.jpg

    In this case, I must create the query with the first, second, third character of the search number and THEN the number + .jpg

    This works fine with PHP, and there are multiple possible combinations. Since I want to do this script database-driven, I can't store in the database, obviously, the substring function which I use in PHP. How can I write a regex to help with this?

    So, for example on this website:

    http://isbn.abebooks.com/mz/39/67/0679728139.jpg

    this book has the last two numbers, then the first two, without the 0 and then the isbn itself.

    In the database I want to store something like:

    http://isbn.abebooks.com/mz/[substr|-2|2]/[substr|1|2]/[str].jpg

    and then my code would replace these things between [ and ] with the appropriate characters in a query.

    Any help would be so much appreciated.

    Thanks

View Complete Thread