Jump to content

eregi() character limits


kektex

Recommended Posts

Hello,

I am a newbie trying to write a script for personal use to check for domain availability at a ccTLD registrar.

I am basically just grabbing the whois results page and looking for status codes which can be "activo" or "suspendido".Otherwise the domain is available (disponible).

 

I tried just using eregi() to look for the status codes and return the status.This wasn´t working, for some reason it always told me everything was DISPONIBLE (available), and then I read at php.net that apparently eregi() has a 255 character limit (see http://www.php.net/manual/en/function.eregi.php#69582 )

 

I tried using preg_match_all but my regex skills aren´t that good because I cant get it to work.

This is the part I´m interested in from a sample whois query:


<b>   Fecha de Vencimiento:</b> 2007-03-06 02:49:24
<b>   Ultima Actualizacion:</b> 2006-02-06 18:25:48
<b>   Fecha de Creacion:</b> 2006-02-06 02:49:24

<b>   Estatus del dominio:</b> SUSPENDIDO


<b>   Servidor(es) de Nombres de Dominio:</b>

 

I tried this and it didn´t work of course  :P :

preg_match_all("/<b>   Estatus del dominio:<\/b> (.+?)/", $url, $output);

 

Can anyone give me a hand with the regex or point me to some other, more suitable function for doing this?

Thanks!

 

Link to comment
Share on other sites

Sorry that I didn't reply sooner, I was trying effigy's fix, but I couldn't get any output and I was just reading up on arrays and stuff to see where my problem was.

Here is the code I have so far:


preg_match_all("/<b>   Estatus del dominio:<\/b> (.+)/", $url, $output);

echo count($output) ."<br>";
print_r($output)."<br>";
echo is_array($output). "<br>";

foreach($output[1] as $keyword){
$keywords .= $keyword."\r\n";
}


echo "$keywords";


 

And this is the output I'm getting:

2
Array ( [0] => Array ( ) [1] => Array ( ) ) 1

Notice: Undefined variable: keywords in C:\Documents and Settings\PC\Mis documentos\PHP\check2.php on line 23

 

The first part of the code (the count() and is_array() ) is just me testing some of the stuff I read.

Why am I getting a "2" in the count()?  The regex should be matching only one string on the page I'm grabbing.

Then I notice that apparently the array is empty :

 [0] => Array ( ) 

Does this mean that the regex is not working?

 

Now, I have to admit I do not understand much of the part where I try to print out the array:

$keywords .= $keyword."\r\n";

I took that from a script I had where I was doing a similar thing and everything worked perfectly.

I have a huge PHP book I just got (Beginning PHP and MySQL) and that's what I'm using to guide myself here.

 

Thanks for your help effigy. I'm just starting to learn PHP and regexes are giving me a hard time.

 

 

 

 

Link to comment
Share on other sites

Is the actual URL in $url? If so, this won't work properly because the regular expression only works on a string--it won't open URLs and files for you.

 

This, however, will work, because the content is in $url:

 

<pre>
<?php

$url = <<<CONTENT
<b>   Fecha de Vencimiento:</b> 2007-03-06 02:49:24
<b>   Ultima Actualizacion:</b> 2006-02-06 18:25:48
<b>   Fecha de Creacion:</b> 2006-02-06 02:49:24

<b>   Estatus del dominio:</b> SUSPENDIDO


<b>   Servidor(es) de Nombres de Dominio:</b>
CONTENT;

preg_match_all("/<b>   Estatus del dominio:<\/b> (.+)/", $url, $output);

echo count($output) ."<br>";
print_r($output)."<br>";
echo is_array($output). "<br>";

foreach($output[1] as $keyword){
$keywords .= $keyword."\r\n";
}


echo "$keywords";

?>
</pre>

 

To use your original code, simply start with these two lines:

 

$content = file_get_contents($url);
preg_match_all("/<b>   Estatus del dominio:<\/b> (.+)/", $content, $output);
...rest of code...

Link to comment
Share on other sites

Yes sorry, I should have specified I already had used file_get_contents:

 

<?php

$dominios = file("dominios.txt");

foreach($dominios as $check){
      $url = file_get_contents('http://www.example.com');

     preg_match_all("/<b>   Estatus del dominio:<\/b> (.+)/", $url, $output);

echo count($output) ."<br>";
print_r($output)."<br>";
echo is_array($output). "<br>";


foreach($output[1] as $keyword){
$keywords .= $keyword."\r\n";
}


echo "$keywords";



}


?>

 

 

Link to comment
Share on other sites

Does $url contain what you expect? Can you post the url, or an attachment of the contents you're trying to parse?

 

Perhaps you need to make the pattern more flexible:

/<b>\s*Estatus del dominio:<\/b>\s*(.+)/

.

Link to comment
Share on other sites

Sorry I take so long to answer, I´m trying to read as much as possible so I don´t come here asking dumb questions :P

I checked $url as you suggested and I noticed that somehow there was some extra whitespace on the file I´m reading the domains from and that´s why I dont get the expected output.

I used trim() to remove the whitespace and now it´s working!

 

Thank you very much for your help effigy!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.