Skip to content

Commit

Permalink
find method fixed. added new method 'contains'.
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1881 committed Aug 4, 2022
1 parent 38cc06d commit 671559e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public function getCookiesArray(int $header_id = null): array
* @return mixed
* @throws Exception
*/
public function find($search_datas, $source = null, bool $remove_line_break = false)
public function find($search_datas, $source = null, bool $remove_line_break = false): object
{
$json = (object)[];
$json->result = false;
Expand All @@ -893,21 +893,41 @@ public function find($search_datas, $source = null, bool $remove_line_break = fa
if (\is_array($search_datas)) {
foreach ($search_datas as $search_data) {
$search_data_regex = \preg_quote($search_data, '/');
if (\preg_match('/' . $search_data_regex . '/si', $source) || $this->contains($search_data_regex, $source)) {
if (\preg_match('/' . $search_data_regex . '/si', $source) || $this->contains($search_data)) {
$json->result = true;
$json->finded[] = $search_data;
}
}
} else {
$search_data = \preg_quote($search_datas, '/');
if (\preg_match('/' . $search_data . '/si', $source) || $this->contains($search_data, $source)) {
if (\preg_match('/' . $search_data . '/si', $source) || $this->contains($search_data)) {
$json->result = true;
$json->finded = $search_datas;
}
}

return $json;
}

/**
* Find string from text
*
* @param mixed $texttosearch
* @param mixed $source
* @return bool
*/
public function contains($search_data, $source = null): bool
{
if (\is_null($source)) {
$source = $this->getResponse();
}

if (\function_exists('str_contains')) {
return str_contains($source, $search_data);
}

return strpos($source, $search_data) !== false;
}

/**
* Getting string from request response or text data
Expand Down Expand Up @@ -1013,18 +1033,6 @@ private function minifyHTML(string $buffer): string
return $buffer;
}

/**
* Find string from text
*
* @param mixed $needle
* @param mixed $haystack
* @return bool
*/
private function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}

/**
* Get const name in class
*
Expand Down

0 comments on commit 671559e

Please sign in to comment.