Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I create a crawler in php which search for a particular string in a webpage and returns whether it is present or not?
Try this function I made, it takes in the pages URL and the string to look for in this URL's content.
<?php
var_dump(searchPage("http://google.com", "Tacos")); //False
var_dump(searchPage("http://google.com", "Google")); //True
function searchPage($url, $string){
$input = file_get_contents($url);
if (strpos($input,$string) !== false) {
return true;
}else{
return false;
}
}
?>
I hope this helped,
Sebastian
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
I tried things like
$query = parse_url($url, PHP_URL_QUERY);
// Returns a string if the URL has parameters or NULL if not
if ($query) {
$url .= '&category=1';
} else {
$url .= '?category=1';
echo "hi";
}
?>
but still i cant seem to find the answer.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Note! I can not use filter_var in my application. Only generic functions.
Perhaps a regex?
<?php
if (is_valid_ipv4($ip)) { ... }
else if (is_valid_ipv6($ip) { ... }
else { ... }
?>
You can just use inet_pton. It returns false if the IP is not a valid IPv6 or IPv4:
function validateIP($ip){
return inet_pton($ip) !== false;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a function that builds a regex based on an array. The problem is that PHP keeps adding backslashes to some of the characters, and it keeps messing up the regex.
Here is my function:
private static $allowedPermissions = [
/*SV*/
'user_add',
'user_edit',
'user_delete',
'user_view'];
$regexrule = '/';
foreach (self::$allowedPermissions as $allowedPermission) {
$regexrule .= '\b'.$allowedPermission.'\b';
if(end(self::$allowedPermissions) !== $allowedPermission) $regexrule .='|';
}
$regexrule .= "/";
return 'regex:'.$regexrule;
It is adding backslashes where I don't expect them:
regex:\/\\buser_add\\b|\\buser_edit\\b|\\buser_delete\\b|\\buser_view\\b|\\bpatient_add\\b|\\bpatient_edit\\b|\\bpatient_delete\\b|\\bpatient_view\\b|\\bmake_per\\b|\\bmake_per_withconfirmation\\b|\\bconfirm_per\\b|\\beval_per\\b|\\beval_per_withconfirmation\\b|\\bconfirm_per_report\\b\/
Backup screenshot of regex
Is there a workaround?
I found out that returning it in json format was adding the backslashes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In PHP, i have strings , similar:
"www.mysite.com/fa/doc/report/67571/مطذح کردنو تت";
"www.mysite.com/fa/571/نهتال اهخع";
"www.mysite.com/fa/";
I want if there are Persian's Chars of string, delete them.
Output:
www.mysite.com/fa/doc/report/67571/
www.mysite.com/fa/571/
www.mysite.com/fa/
How can i do this?
You should try this code.
<?php
echo remove_persian("www.mysite.com/fa/doc/report/67571/مطذح کردنو تت");
function remove_persian($text)
{
return preg_replace('#[^a-zA-Z0-9./]#', '', $text);
}
This will output like this:
www.mysite.com/fa/doc/report/67571/
You can use a regex :
$clean = preg_replace('[^a-zA-Z\/\d\s:]', '', $url);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I don't know exactly how to say this, I'll use an example.
//[$var:Username|n] will print username with n length
$myText = 'The participants are [$var:Username|10], [$var:Username|8], and [$var:Username|6]';
$username = array('Alexandrite', 'Maximillian', 'Angelina');
$result = someFunction('[$var:Username|n]', $username, $myText);
echo $result;
//The participants are Alexandrit, Maximill, and Angeli
Any idea how to do this? Maybe using preg_replace?
I'm interested to know why you would even need to do this. Regardless:
preg_replace_callback('/\[\$var:Username\|(\d+)\]/', function ($match)
use (&$count, $username
) {
return substr($username[$count++], 0, $match[1]);
}, $myText);