galayman Posted November 24, 2007 Share Posted November 24, 2007 Hi all, i'm a beginner who love php and have this problem, i'm already download lots of ebook of php to solve this problem, but i think i do not know how to solve this. This is my problem : I have a data and i put it all together inside a variable called DATA, this is what inside of $DATA after i gather all the data that i needed. $DATA = " copyright of me and you 2007 and the others bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537% thank you all friend and everyone data date and year 2007 "; i need to only capture this data and remove the others: bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537% and split it and make each data inside another variable, like this : $a = bread 15.22 44.97% $b = crumbs 15.532 6.47% $c = apple 146.932 6.555% $d = coffe 83.72 6.537% can this be done? and also the data that i try to capture is random, but always with this type : letter - number - number like bread - 15.22 - 44.97% Thank you for your help and sorry for my english. Best Regards Quote Link to comment Share on other sites More sharing options...
LordOrange Posted November 24, 2007 Share Posted November 24, 2007 how is the data inputted? Quote Link to comment Share on other sites More sharing options...
galayman Posted November 24, 2007 Author Share Posted November 24, 2007 This is how i get the data <? $GET = file_get_contents("hxxp://somesite"); $GET = strip_tags($GET); ?> Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Well, if the copyright text is the exact same every time, then you can chop that out of the original data, then explode the variable $DATA using space (" ") as the delimiter. So, let's say you get the copyright and thank you stuff out. We are left with: <?php $DATA = "bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537%"; $pieces = explode(" ", $DATA); $a = $pieces[0] . " " . $pieces[1] . " " . $pieces[2] . " " . $pieces[3]; $b = $pieces[4] . " " . $pieces[5] . " " . $pieces[6] . " " . $pieces[7]; $c = $pieces[8] . " " . $pieces[9] . " " . $pieces[10] . " " . $pieces[11]; $d = $pieces[12] . " " . $pieces[13] . " " . $pieces[14] . " " . $pieces[15]; ?> PhREEEk Quote Link to comment Share on other sites More sharing options...
galayman Posted November 24, 2007 Author Share Posted November 24, 2007 Thank you for you reply, it help. may i ask another problem? from this variable : $DATA = " _SOME OTHER RANDOM DATA_ copyright of me and you 2007 and the others bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537% thank you all friend and everyone data date and year 2007 _SOME OTHER RANDOM DATA_ "; from the variable, can php search this string bread and remove any character before the bread string, and also search thank you and remove any character after the thank you string. so inside the $DATA is always = bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537% thank you even there is a lot random of data before the string bread and after the thank you string I hope my question is understandable, still learing english. Best Regards Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Your English is quite good, I understand you perfectly. Yes, PHP can find those string positions and help you remove them. I am going to get some sleep now, so I cannot help with writing that part of the code. There are many here capable of helping you, so be patient and someone will be along. PhREEEk Quote Link to comment Share on other sites More sharing options...
galayman Posted November 24, 2007 Author Share Posted November 24, 2007 Thank you, have a good night sleep. Quote Link to comment Share on other sites More sharing options...
galayman Posted November 25, 2007 Author Share Posted November 25, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
rab Posted November 25, 2007 Share Posted November 25, 2007 Use constants from the data and user preg_match with a regular expression built from that. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 25, 2007 Share Posted November 25, 2007 simple answer is yes - long answer is yes but what if the preceeding characters containe the same words you are looking for???? in order to perform waht you want a regular expression is required - and it needs some rules inorder to work properly... IF the code you want stripping won't contain those words then this should do the trick... <?php $DATA = " _SOME OTHER RANDOM DATA_ copyright of me and you 2007 and the others bread 15.22 44.97% crumbs 15.532 6.47% apple 146.932 6.555% coffe 83.72 6.537% thank you all friend and everyone data date and year 2007 _SOME OTHER RANDOM DATA_ "; $str = preg_repace('/(.*)bread(.*)?thank you(.*)/s','bread$2'); ?> have a play with that... Quote Link to comment Share on other sites More sharing options...
galayman Posted November 25, 2007 Author Share Posted November 25, 2007 Thank you, Topic solved. i'm using preg_replace, and also explode. I hope good thing happen to good people like all of you who helped others. Quote Link to comment 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.