lfernando Posted June 15, 2011 Share Posted June 15, 2011 Hi all, I really hope someone out there can help me out! I have a string with hundreds of list items and they all have a unique id, they look like this: <LI id="1234_tab2_[234]"> apples <LI id="1234_tab2_[45]"> sun <LI id="1234_tab2_[95]"> sky <LI id="1234_tab2_[26]"> grass I need to find each id and look up the value in a SQL database, which look like this list_item_id list_item_value 1234_tab2_[234] red 1234_tab2_[45] yellow 1234_tab2_[95] blue 1234_tab2_[26] green Then i have to replace each list item with the value pulled up from the database, like this: red is for apples yellow is for sun blue is for sky green is for grass I managed to do this using a series of for loops but it takes a long time to load the pages with over 300 list items The reason for this is that I dont know much about regex so i'm just using strpos and substr. Please help!! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/239469-match-list-item-ids/ Share on other sites More sharing options...
fugix Posted June 15, 2011 Share Posted June 15, 2011 if you want to use a regular expression to isolate the id's you can use $regexp = '/\d+\_[a-zA-Z0-9]+\_\[(\d)+\]/gi'; Quote Link to comment https://forums.phpfreaks.com/topic/239469-match-list-item-ids/#findComment-1230191 Share on other sites More sharing options...
xyph Posted June 15, 2011 Share Posted June 15, 2011 You don't need to escape underscores. Quote Link to comment https://forums.phpfreaks.com/topic/239469-match-list-item-ids/#findComment-1230231 Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 You don't need to escape underscores. True Quote Link to comment https://forums.phpfreaks.com/topic/239469-match-list-item-ids/#findComment-1230263 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.