K
K
KRHD2015-11-03 09:30:35
PHP
KRHD, 2015-11-03 09:30:35

How to implement whole word search in txt via PHP?

And so, there is a text file. domains.txt
It contains domains that are allowed to install the script, but not the essence.
Now I'm doing auto-activation.
In general, how to make it search in this txt if there is a domain, for example, vk.com.
I tried using strpos, but it did not work out very well, it looked for every letter :(
if there is, then the error is 'This domain is activated!';
if not, then 'The domain was successfully activated!';

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
KRHD, 2015-11-03
@KRHD

Andrew : Thank you!
Did it like this:

$txt = file_get_contents("domains.txt");
$domain = $_GET['domain'];
$explode = explode(":", $txt);
if (in_array($domain, $explode)) {
    echo "Данный домен активирован!";
}

N
Nikita, 2015-11-03
@Rema1ns

preg_match

A
Andrew, 2015-11-03
@R0dger

$text = 'test.ru
vk.com
redis.org
';

preg_match('/vk\.com/mi', $text, $matches);
if (count($matches) > 0) {
echo "true"; }

I
Ilya Beloborodov, 2015-11-03
@kowap

Or so at all

<?php 
     $domain='vk.com';
     $txt=file_get_contents("domains.txt");
     if(stristr($txt, $domain))
          echo 'Домен активирован';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question