Asheeown Posted March 31, 2009 Share Posted March 31, 2009 I currently have this string preg_match('/data: (.*);/', $Contents, $Matches); It doesn't work the way I want it to because sometimes data: 'wildcard'; appears more than once, I need more info behind the word data so it should look like this: new Listview({template: 'item', id: 'sells', name: LANG.tab_sells, tabs: tabsRelated, parent: 'WILDCARD', extraCols: [Listview.extraCols.cost], note: WILDCARD, data: Wherever WILDCARD appears it just needs to be set to a wildcard. Problem is I wasn't the original person to right this regex code I just modded it to fit my needs but I tried to do this one and the array $Matches comes up empty everytime. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/ Share on other sites More sharing options...
MadTechie Posted March 31, 2009 Share Posted March 31, 2009 Sorry i'm a little confused.. what are you trying to check for ? maybe a few examples and bolding the thing you need to check for.. are you trying to get the data between "data: " and the ";" ? if so try this preg_match_all('/data: ([^;]*);/s', $Contents, $Matches, PREG_PATTERN_ORDER); $Matches= $Matches[1]; echo "<pre>"; var_dump($Matches); Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798226 Share on other sites More sharing options...
Asheeown Posted April 1, 2009 Author Share Posted April 1, 2009 Yeah I'm getting all the data inbetween data: and the semicolon at the end. Only I need to add more text before because it's picking up more than one data: in the string. Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798246 Share on other sites More sharing options...
MadTechie Posted April 1, 2009 Share Posted April 1, 2009 Your need to give an example as i'm not sure what you mean! Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798260 Share on other sites More sharing options...
Asheeown Posted April 1, 2009 Author Share Posted April 1, 2009 You got it: Here is the full string of data inside all the text: new Listview({template: 'item', id: 'sells', name: LANG.tab_sells, tabs: tabsRelated, parent: 'lkljbjkb574', extraCols: [Listview.extraCols.cost], note: sprintf(LANG.lvnote_createafilter, '/?items&filter=cr=129;crs=0;crv=66'), data: [{id:5956,name:'6Blacksmith Hammer',level:1,reqlevel:1,dps:0.8,speed:2.00,slot:21,source:[5],classs:2,subclass:14,stack:[1],avail:-1,cost:[18]},{id:2324,name:'6Bleach',level:5,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[25]},{id:6260,name:'6Blue Dye',level:10,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[50]},{id:2320,name:'6Coarse Thread',level:5,slot:0,source:[5],classs:7,subclass:5,stack:[1],avail:-1,cost:[10]},{id:10648,name:'6Common Parchment',level:40,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[125]},{id:6217,name:'6Copper Rod',level:5,slot:0,source:[5],classs:7,subclass:12,stack:[1],avail:-1,cost:[124]},{id:3371,name:'6Empty Vial',level:1,slot:0,source:[2,5],sourcemore:[{t:7,ti:4395,n:'Dalaran'}],classs:7,subclass:11,stack:[5],avail:-1,cost:[20]},{id:6256,name:'6Fishing Pole',level:1,dps:1.0,speed:3.00,slot:17,source:[4,5],sourcemore:[{t:5,ti:9452,n:'Red Snapper - Very Tasty!',c:3524,c2:1}],classs:2,subclass:20,stack:[1],avail:-1,cost:[23]},{id:39354,name:'6Light Parchment',level:1,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[15]},{id:2678,name:'6Mild Spices',level:5,slot:0,source:[5],classs:7,subclass:11,stack:[5],avail:-1,cost:[10]},{id:2901,name:'6Mining Pick',level:4,reqlevel:1,dps:1.5,speed:2.00,slot:21,source:[5],classs:2,subclass:14,stack:[1],avail:-1,cost:[81]},{id:6270,name:'6Pattern: Blue Linen Vest',level:12,slot:0,skill:55,source:[5],classs:9,subclass:2,stack:[1],avail:1,cost:[200]},{id:6325,name:'6Recipe: Brilliant Smallfish',level:5,slot:0,skill:1,source:[5],classs:9,subclass:5,stack:[1],avail:-1,cost:[40]},{id:6328,name:'6Recipe: Longjaw Mud Snapper',level:15,slot:0,skill:50,source:[5],classs:9,subclass:5,stack:[1],avail:-1,cost:[400]},{id:2604,name:'6Red Dye',level:10,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[50]},{id:4289,name:'6Salt',level:10,slot:0,source:[5],classs:7,subclass:6,stack:[1],avail:-1,cost:[50]},{id:6529,name:'6Shiny Bauble',level:10,slot:0,source:[4,5],sourcemore:[{t:5,ti:9452,n:'Red Snapper - Very Tasty!',c:3524,c2:1}],classs:0,subclass:-3,stack:[1],avail:-1,cost:[50]},{id:30817,name:'6Simple Flour',level:5,slot:0,source:[5],classs:7,subclass:11,stack:[5],avail:-1,cost:[25]},{id:7005,name:'6Skinning Knife',level:4,reqlevel:1,dps:1.3,speed:1.60,slot:13,source:[2,5],sourcemore:[{t:3,ti:33857,n:'Crate of Meat',q:1}],classs:2,subclass:14,stack:[1],avail:-1,cost:[82]},{id:2880,name:'6Weak Flux',level:5,slot:0,source:[5],classs:7,subclass:11,stack:[1],avail:-1,cost:[100]}]}); I need everything from data: to the semicolon at the end the parent ID "parent: 'lkljbjkb574'" is never the same so that needs to be a wildcard and also "/?items&filter=cr=129;crs=0;crv=66" is never the same so that needs to be a wildcard also. Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798307 Share on other sites More sharing options...
MadTechie Posted April 1, 2009 Share Posted April 1, 2009 what are you trying to check for ? by the sounds of thing you just want to check its valid!.. but also you want to extract details! telling me its changes and need to be a wildcard (i know what wildcard is thus if it changes i know its going to be a wildcard) With all that in-mind i'll have to assume you want parent:' to ' sprintf(LANG.lvnote_createafilter, ' to ') data: to ; i'll also assume the order is the seam each time! in that case try <?php preg_match('/parent:\s*\'([^\']*)\'.*?sprintf\(LANG.lvnote_createafilter, \'([^\']*)\'\).*?data: ([^;]*);/si', $Contents, $Matches) $parent= $Matches[1]; $createafilter= $Matches[2]; $data= $Matches[3]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798330 Share on other sites More sharing options...
Asheeown Posted April 1, 2009 Author Share Posted April 1, 2009 $Matches[3] works beautifully with that regex statement and it filters out all the other data:'s, thanks very much Mad. Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798332 Share on other sites More sharing options...
Daniel0 Posted April 1, 2009 Share Posted April 1, 2009 Looks to be JSON. Why don't you just decode it? Quote Link to comment https://forums.phpfreaks.com/topic/151994-solved-two-wildcards/#findComment-798659 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.