Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to find words from .txt file using specific pattern
Old 07-22-2010, 11:30 AM How to find words from .txt file using specific pattern
Junior Talker

Posts: 1
Trades: 0
It's my first post here, so hi all.
Anyway, I am trying to work this out, but can't do this alone. I have a specific line of text, I already replaced it with something more user-friendly using this piece of code:

<?php

$algorytm = ",,D-,,R,-,,T,-,P,,-F,,,¤,P,,-,I,,-,,,F-,,,E¤,,,G-,,T,-,,S,-O,,,-,,E,¤,,,E,-D,,,,-,P,,,-R,,,,-,,N,,¤,,,S,-,,A,,-,,L,,¤,,,,M-,,,A,-,,,S,-,,F,,-,,,B,¤,,,,G-,,,T,-,E,,,";

$algorytm2 = str_replace(",", "?", $algorytm);
$algorytm3 = str_replace("¤", "-", $algorytm2);
$algorytm4 = str_replace("-", "<br>", $algorytm3);
echo $algorytm4;

?>

The result is here: http://p.netserwer.pl/words/
The pattern itself always contains 30 lines that contains words made from 3, 4 or 5 letters. There is always only 1 letter assigned, the ? are wildcards and anything can be placed here. What do I need ? - example:

??D RED
??R? BIRD
??T? BITS

I am trying to assign a word to every line next using the pattern where ??D is any 3-letters word that ends with D etc. I have also made wordlists:
http://p.netserwer.pl/words/3.txt
http://p.netserwer.pl/words/4.txt
http://p.netserwer.pl/words/5.txt

To be honest, I am not a good programmer and have no idea how to make it. Any help or advice will be appreciated.
firian is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-26-2010, 08:16 PM Re: How to find words from .txt file using specific pattern
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Alright! So you want to make a script that guesses words, such as if the user enters 'D' it will guess 'red'?

First off, if that's what you want, you could use the MySQL LIKE operator and do something like this:

$something = mysql_fetch_array(mysql_query("SELECT fullWord FROM `words` WHERE $enteredWord LIKE '%$enteredWord%'"));$something=$something[0];

But I'm not exactly sure if that's what you want. Try to organize your question as a story. Like "User types in 'd' and when they click Generate, 'Red' is there.".

By the way, welcome to Webmaster-Talk! I hope you will find what you need, I will be glad to help you in the future, just PM me

EDIT - Seeing as you're using a text file with all the values you may need (which is very, very slow when parsing), you could implode that file, separated by ", and explode it again as an array I guess, then use in_array?
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 07-26-2010 at 08:19 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-02-2010, 10:36 AM Re: How to find words from .txt file using specific pattern
Average Talker

Posts: 22
Trades: 0
Please set us how will be the input string to search and how will be the output from the file.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
katierosy is offline
Reply With Quote
View Public Profile Visit katierosy's homepage!
 
Reply     « Reply to How to find words from .txt file using specific pattern
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34043 seconds with 12 queries