warrenk Posted February 17, 2007 Share Posted February 17, 2007 http://www.website.com/product-xx11-p-16191.html http://www.website.com/product-xx22-p-16192.html (etc) I am trying to strip out the number ie. 16191, 16192, etc) into a field. The number is always just before the '.html' and right after '-p-'. Any suggestions? If it requires more then one SQL...not a problem. Appreciate any help! Warren Quote Link to comment https://forums.phpfreaks.com/topic/38964-require-sql-to-strip-data-from-a-field/ Share on other sites More sharing options...
shoz Posted February 18, 2007 Share Posted February 18, 2007 If the url is always in the pattern you posted you should be able to use the following. SELECT SUBSTRING(SUBSTRING_INDEX(columnname, '.', 3), LOCATE('-p-', columnname)+3) AS num FROM tablename If the '-p-' is always the same number of characters from the beginning of the url string you can hardcode the second argument. Using PHP a better solution may be <?php preg_match('/-p-(\d+)\.html/i', $row['columname'], $matches); echo $matches[1]; ?> EDIT: query edit. Quote Link to comment https://forums.phpfreaks.com/topic/38964-require-sql-to-strip-data-from-a-field/#findComment-187608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.