Jump to content

cyfer

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

About cyfer

  • Birthday 12/23/1985

Profile Information

  • Gender
    Male
  • Location
    Ireland

cyfer's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Do you know what.. I'm a fool.. The test actually did return those letters.. Don't know what i was doing to think i didn't.... So it is actually my ajax script transporting the text back to a another page that mess up.. I'll have a look at this.. Don't mind any of the above
  2. Note: I tried disgarding the whole file import function and just do a $test_string = "ABC09988 Køtæv Blah 5544 5410"; and do the preg_match on that... Still same problem. I don't recognize the letters as letters i guess...... :'( I tried the below in the hope it would then include those letters. But i guess php don't recognizes it cause that doesn't work either: ([a-zA-Zæøå].*[a-zA-Zæøå])
  3. Hey.. So i'm checking it out with the real data file just now. And it works like a charm. It's pretty fast too (i feared it being slow with so much data to search through)... Only problem is that some of the text is with foreign letters which is not in the english alphabet. Hence it wont collect that text Example: ABC09988 Køtæv Blah 5544 5410 ... These letters Ø and Æ aren't collected as letters. Hence it will stop already at the K and figure the rest is not letters. How the **** do i get around this?? ???
  4. Well whatever the process.. I am thankful for your help I'm looking forward to testing it out in production on Monday!
  5. Okay so i've been doing some investigation on google and haven't been able to come up with anything that was doing what i want or close so i could modify it (even that.. please note i'm no good at javascript) What i need is as follows. Page 1: Here i have a form in which i have several input fields. Next to one of these should be a button the user can press. This should do one of two things (whatever you can manage). One solution - take the text put into the field and open a popup window where the text will be available via ex get or post so i can fetch it in my php script. This php script returns some values which needs to go back to page 1 and be put into the other fields. Another solution would be to not open any popup window but do the entire process in the bacground loading the php script i've got. But this sounds pretty advanced?? Thanks in advance. I appreciate your help.
  6. Hehe it was nagging you wasn't it Well.. Yeah I think so - almost sure. Honestly I haven't got the exported file with me at the moment. I will however have access to it on Monday. So I will be looking into it there. It is working like a charm now so I won't be messing more with it until Monday when I will be able to use it in production with the real txt file.
  7. Alright yeah you can surely do it like that.. And then just add the maximum number i would guess it could contain. I did however make a couple of changes to the code i posted just before as it was not giving the correct output (just posting for historic reference). Code (incuding the new changes): $search = "ABC11923"; $handle = @fopen("sc_export.txt", "r"); if ($handle) { while (!feof($handle)) { $string = fgets($handle, 4096); if( preg_match("/(" . $search . ") ([a-zA-Z]*.[a-zA-Z]*.[a-zA-Z]*) (.*)/",$string,$result)) { $check_return = "true"; echo $result[0] . "<br>"; echo $result[1] . "<br>"; echo $result[2] . "<br>"; echo $result[3]; } } fclose($handle); } Output being: ABC11923 Fiiiz KEla dag +43 323332 3234 33 ABC11923 Fiiiz KEla dag +43 323332 3234 33 This does exactly what i was looking for. I will let this topic open for some time if anyone should come along with a more sofisticated solution to the regex pattern But you have been a great help. Thank you so much !
  8. Nevermind this.. It is of course obvious how to do it.. Sorry for my stupidity Okay so this is how the code now looks, which works smoothly: <?php $search = "ABC11923"; $handle = @fopen("sc_export.txt", "r"); if ($handle) { while (!feof($handle)) { $string = fgets($handle, 4096); } fclose($handle); } preg_match("/(" . $search . ") ([a-zA-Z]*.[a-zA-Z]*) (.*)/",$string,$result); echo $result[0] . "<br>"; echo $result[1] . "<br>"; echo $result[2] . "<br>"; echo $result[3]; ?> Output: ABC11923 Fiiiz KEla dag +43 323332 3234 33 ABC11923 Fiiiz KEla dag +43 323332 3234 33 So back to the important second question i was asking about: I noticed if i were to put a 3rd line of text into the the line it returns it in the 3rd array instead of the 2nd. Is there no way to make it not care about spaces and just capture all that starts with letters in the 2nd array?
  9. Ah yes of course.. Okay so this is what i've got so far which works. Two things though. Firstly: I would want the script to recognize which returns the true result and then put it into a variable for each array. I don't get how to do that. Secondly: I noticed if i were to put a 3rd line of text into the the line it returns it in the 3rd array instead of the 2nd. Is there no way to make it not care about spaces and just capture all that starts with letters in the 2nd array? The code so far: <?php $search = "ABC11923"; $handle = @fopen("sc_export.txt", "r"); if ($handle) { while (!feof($handle)) { $string = fgets($handle, 4096); preg_match("/(" . $search . ") ([a-zA-Z]*.[a-zA-Z]*) (.*)/",$string,$result); echo "<pre>"; print_r($result); echo "</pre><br />"; } fclose($handle); } ?> Returns: Array ( ) Array ( ) Array ( ) Array ( [0] => ABC11923 Fiiiz KEla dag +43 323332 3234 33 [1] => ABC11923 [2] => Fiiiz KEla [3] => dag +43 323332 3234 33 )
  10. Yeah sorry i did however try to implement file imput which only returns an error: Warning: Invalid argument supplied for foreach() <?php $search = "ABC10239"; $handle = @fopen("sc_export.txt", "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); foreach($buffer as $string) { echo "$string<br/>"; preg_match("/(" . $search . ") ([a-zA-Z]*.[a-zA-Z]*) (.*)/",$string,$result); echo "<pre>"; print_r($result); echo "</pre><br />"; } } fclose($handle); } ?> Also i noticed that the test file i have with only those 4 lines in it takes quite some time for the script to load.. So i'm afraid that it will completely stall when when i am to use the real file with several 100 lines in it...
  11. I am not quite sure how to do this. I really appreciate your help. Would you be kind enough to provide an example of how this might be put into work with the rest of the code? Bearing in mind that i only want the array containing the result from the search. Thank you so much.
  12. Do you know what.. That looks amazing.. Almost what i was looking for. I think you misunderstood me slightly there.. I only need to pull out one line - being the line of which it matches the search. The example could be that i search for the line "ABC05234" which could be stated in for example $search_query. It finds this line: ABC05234 Text text 47 37 83 93 And then returns: Array ( [0] => ABC05234 Text text 47 37 83 93 [1] => ABC05234 [2] => Text text [3] => 47 37 83 93 ) ... Also the info would have to be pulled out from the txt file.. So the function should import the data in the txt file and search in that..
  13. Hi guys, I hope someone will be able to help me on this one. I'm completely a newbie when it comes to regular expressions. After having looked google up and down for tutorials, guides and manuals for several hours i am still somewhat blank on what to do (i have attempted numerous times and failed :\). Okay so here goes. I have an exported .txt file with a bunch of info in it (it can't be exported in any other state than showed beneath so this will have to do). The info as you can see is fairly similar formated. Please see the sc_export.txt example for reference. 1. I will do a search for "ABC05234 " 2. This should return the stuff from that line in two arrays - array1 = Text text - array2 = 47 37 83 93 And that is basically it. As you can see the first array will always have the text part in it and the second part the numbers (phone numbers). Please bare i mind that a search on for example "ABC10239" would return a more complex line to be pulled out. Example of the text file to search in (File: sc_export.txt): ------------------------------------------------------- ABC02938 Text 3939 4940 ABC05234 Text text 47 37 83 93 ABC10239 Text-text 39483948 ABC10239 Text.text +44 3943 283948 ....data continues with more simular data. Howefer there can be a difference in how many spaces there are between the data. ------------------------------------------------------- I thank all of you for your help in advance. Christoffer
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.