Match for a word in a text with the PHP script

Started by nikolaymartin, May 05, 2020, 09:03:05 AM

Previous topic - Next topic

nikolaymartin

I have an applications developed with PHP. I have a big text file where I want to match for a word but this can be change in the feature. How can I match a word in PHP?

deanwebb

Is this where the word you want to match for changes? I'm not understanding the question.
Take a baseball bat and trash all the routers, shout out "IT'S A NETWORK PROBLEM NOW, SUCKERS!" and then peel out of the parking lot in your Ferrari.
"The world could perish if people only worked on things that were easy to handle." -- Vladimir Savchenko
Вопросы есть? Вопросов нет! | BCEB: Belkin Certified Expert Baffler | "Plan B is Plan A with an element of panic." -- John Clarke
Accounting is architecture, remember that!
Air gaps are high-latency Internet connections.

Otanx

Would need more details on what exactly you are trying to do. Just a True/False word is in text? I don't know about PHP, but python would be something like;


long_text = "This is the text that you are searching to find the specific text you want in this wordy string"
find_word = " word "
print(find_word in long_text)


That would return False because the word "word" does not exist in that string. Note that the find_word variable has spaces around the word. This prevents it from matching "wordy" If you left the spaces out it would match if it found those four characters in a row.

May I ask why PHP? Python seems to be the preferred language now which is why I am learning it.

-Otanx

edizgeorgi

#3
There are different functions and ways to match a word in PHP. Best way is using preg_match() function. In the following example we will search the forum word in the $bigtext content.
preg_match('/forum/',$bigtext)
Look: https://www.networking-forums.com/programming-goodies-and-software-defined-networking/match-for-a-word-in-a-text-with-the-php-script