0

I am developing a telegram bot that uses PHP to send data to the client. This is a telegram bot that allows the user to check if a domain name is already registered or not. If not registered it lets the user register it, if already registered it returns the whois information of the registered domain name.

This is partial part of my code:

 if($inText) {
    $domain = trim($inText);
    if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7);
    if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);
        if(ValidateIP($domain)) {
        $caption = LookupIP($domain);
    }
    elseif(ValidateDomain($domain)) {
        $caption = LookupDomain($domain);
        //$errorchars = array('no match','No results','NOT FOUND');
        //strtolower($errorchars)
        if(strpos(strtolower($caption),'no match') !== false or strpos(strtolower($caption),'no results') !== false or strpos(strtolower($caption),'not found') !== false){
            $caption = "
             Domain $domain is available to register

            You can register it here :
             http://something.com/?register=$domain



     static text 
      static text
  ☎️  static text
        ";}
            else{
                $caption = "
    Dear user,

 the domain $domain is already registered! 

 Domain Whois info:

$caption 

 The Domain name is already registered                    

     static text 
      static text
  ☎️  static text
";
        }
    }
    else $caption = "Entry is invalid";
}
    $photo = "https://kmc.im/glassbot/1.jpg";
    //$caption = LookupDomain ($inText);

    $output1 = "

     static text 
      static text
  ☎️  static text
    ";

    $sendP = sendPhoto($cid, $photo, $botapi ,$output1,$encodedMarkup) ;
    $sendP1 = sendMessage($cid, $caption, $botapi ,$encodedMarkup) ;
    $sendP2 = sendMessage($adminID, "$caption \n ID : $cid \n User : @$uname", $botapi ,$encodedMarkup) ;
}


?>

The code works prefectly and it does the job right.

Where it says:

Domain Whois info:

$caption  

is when a domain name is already registered, $caption returns the whois information.

What I want to do is the add a function that saves the value of $caption into a text file. So I can keep a record of it.

I have been struggling with it for a while and couldn't get it right.

Your help is appreciated.

Thank you

Gerrit Fries
  • 145
  • 1
  • 13
Arta S
  • 134
  • 1
  • 11

1 Answers1

2

You can use file_put_contents function to save data into the file with only one command.

Example:

file_put_contents("yourfilenametosavedata.txt", $caption);

That's it.

Xplatforms
  • 2,102
  • 17
  • 26
  • So I just add this line after $caption? How can I combine them? – Arta S Sep 15 '17 at 10:21
  • I am not an expert in PHP. I am not sure how to combine this code with mine. – Arta S Sep 15 '17 at 10:38
  • 1
    @ArtaS, yes. For example after line "$sendP1 = sendMessage($cid, $caption, $botapi ,$encodedMarkup) ;" add Line: file_put_contents($domain.".txt", $caption); This will save file "entereddomainname.txt" in the same folder there your php file is. Or use this line: file_put_contents($cid."_".$domain.".txt", $caption); Then you will get file called "clientid_entereddomainname.txt" – Xplatforms Sep 15 '17 at 10:51
  • Thanks for that. Cheers – Arta S Sep 15 '17 at 11:20