firstminister Posted August 20, 2012 Share Posted August 20, 2012 Hi everyone.. sweet ppl, i have a long time, looking for a script which make this: i need to filter, data of one input from the other one input! for example: I write phone numbers (per line) on the first textarea, and on the other, i put phone numbers that i want to remove from the first textarea, and print results of cleaned numbers on the same page.. someone can help me please! sorry for english errors, im hispanic Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/ Share on other sites More sharing options...
darkfreaks Posted August 20, 2012 Share Posted August 20, 2012 why not use Regex to match the phone number // validate a phone number if( !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone) ) { echo 'Please enter a valid phone number'; } Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370760 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 thanks for answering: I have a form with 2 textareas so, i want is, set one list of numbers on the first textarea, and, in the second textarea set some phone numbers which I want to remove from that list! u got it? how can i do it? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370761 Share on other sites More sharing options...
darkfreaks Posted August 20, 2012 Share Posted August 20, 2012 http://stackoverflow.com/questions/841722/append-text-to-input-field Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370762 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 Bro is that working sccript for me? im looking for remove some phone numbers, from a phone numbers list, with one script, i dont understand that link.. Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370763 Share on other sites More sharing options...
darkfreaks Posted August 20, 2012 Share Posted August 20, 2012 well bro i don't understand what your saying no offfense. here is a post which i think is a similar thing you might be on about http://forums.phpfreaks.com/index.php?topic=352961.0 Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370764 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 hahhaaha.. look my friend: I have a Phone numbers list right, so, i want remove some numbers from that list... What is my idea? make a form with two input, in one input put the phone numbers list, and in the other one, put the numbers which i want to remove from that list.. u got it? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370767 Share on other sites More sharing options...
MMDE Posted August 20, 2012 Share Posted August 20, 2012 preg_replace("/$phone_number/", "", $phone_number_list); ^ This will leave empty lines, so you might want to make sure you remove those empty lines too. http://php.net/manual/en/function.preg-replace.php Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370769 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 Maybe this is a little over the top, creating arrays etc. <?php if (isset($_POST['listnumbers'])){ $listnumbers = nl2br(trim($_POST['listnumbers'])); $listnumbers = explode('<br />', $listnumbers); $Newlist=array(); foreach ($listnumbers as $numbers){ $numbers = str_replace("\r", "", $numbers); $numbers = str_replace("\n", "", $numbers); $numbers = preg_replace('~^(\<br /\>,/\n)+~', '', $numbers); $Newlist[] = $numbers; } $searchnumber = trim($_POST['searchnumber']); if (in_array($searchnumber,$Newlist)){ $number_key = array_search($searchnumber,$Newlist); unset($Newlist[$number_key]); } } ?> <html> <body> <?php echo "<pre>"; echo "<br />listnumbers<br />"; print_r($listnumbers); echo "<br />Newlist<br />"; print_r($Newlist); echo "<br />POST<br />"; print_r($_POST); echo "</pre>"; ?> <form method="post" action=""> <textarea name="listnumbers"> <?php echo (isset($Newlist)? implode(' ', $Newlist):''); ?> </textarea><br /> <textarea name="searchnumber"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370775 Share on other sites More sharing options...
Christian F. Posted August 20, 2012 Share Posted August 20, 2012 firstminister: Look into "array_unique ()" as that will do exactly what you're looking for. Drummin: Why replace the newlines with br tags, only to explode on them? Much better to explode the newlines right away. Your code could easily have been reduced to three lines, using the array_unique () and stripping away all unnecessary operations. Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370804 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 with the drummin answer i can filter the numbers from a number list? what is the variable of numbers to filter input's? can help me with entire code? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370859 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 So ChristianF can you help me with the code? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370863 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 OH Drummin I got it, let me check Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370864 Share on other sites More sharing options...
Christian F. Posted August 20, 2012 Share Posted August 20, 2012 I have given you the tools you need to learn how to do this yourself, in the proper way. I don't have the time nor the inclination to write the code for you, unless you want to pay for my services. Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370870 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 Ok, I checked the code, but this is the problem.. That script just filters one number from the list.. i need to filter, a large amount of numbers from the list... how can i do? thanks Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370872 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 Christian I understand.. but like is just a simple script.. anyway if you can help me to modify it and can filter more numbers, i'll be thankful.. Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370874 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 As pointed out, for single number removal a simple preg_replace will do the job. <?php if (isset($_POST['listnumbers'])){ $phone_number_list = trim($_POST['listnumbers']); $phone_number = trim($_POST['searchnumber']); $phone_number_list = preg_replace("/$phone_number/", "", $phone_number_list); $phone_number_list = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $phone_number_list); } ?> <html> <body> <form method="post" action=""> <textarea name="listnumbers"><?php if (isset($phone_number_list)){echo "$phone_number_list";} ?> </textarea><br /> <textarea name="searchnumber"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html> If however if your needing to remove a list of numbers from another list of numbers this approach won't work and you will probably need to build an array for each input and then filter out matches within a foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370875 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 This should do it. <?php if (isset($_POST['listnumbers'])){ $Newlist = explode(PHP_EOL, trim($_POST['listnumbers'])); $Searchlist = explode(PHP_EOL, trim($_POST['searchnumbers'])); $Newlist = array_diff($Newlist,$Searchlist); $phone_number_list = implode(PHP_EOL,$Newlist); } ?> <html> <body> <form method="post" action=""> <textarea name="listnumbers"><?php if (isset($phone_number_list)){echo "$phone_number_list";} ?> </textarea><br /> <textarea name="searchnumbers"></textarea><br /> <input type="submit" value="Check Number" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370883 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 mmm, yes, im trying to filter a large phone number list, and the page appears in blank.. Doesn't allow to filter so much numbers.. i can do it attachting a text file? and set the numbers to filter on an input? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370884 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 I'm not aware of limitations to array_diff but not tried it with a large list. Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370885 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 let me check this new code u posted Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370889 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 Oh perfect! it works, but how can I show the new filtered numbers, in the same page, not in the textarea and per line? example: Results filtered numbers: 12345 1234576 564476 3433243 66655434 Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370892 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 Copy that isset echo line I have between the textarea tags an place where you want it. If you are going to use it for display, you'll probably want to change that last line to implode with a break tag. $phone_number_list = implode("<br />",$Newlist); Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370894 Share on other sites More sharing options...
firstminister Posted August 20, 2012 Author Share Posted August 20, 2012 oh, we have a problem, the code doesn't filter the number 6 :S why? Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370900 Share on other sites More sharing options...
Drummin Posted August 20, 2012 Share Posted August 20, 2012 Huh? You put in these number into the first textarea and 6 into the second textarea and it pulls that six out. What are you talking about? can you give me some examples? 12345 1234576 6 564476 3433243 66655434 Quote Link to comment https://forums.phpfreaks.com/topic/267323-filter-data-from-one-input/#findComment-1370902 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.