Reputation: 51
I have a question about pre_match in PHP.
This is the code:
function get_ayalon($input) {
$escaped_input = rawurlencode($input); // RFC 3986!
$ayalon_result = get_URL("http://arabdictionary.huji.ac.il/Matrix.Arabdictionary/Search.aspx?RadioArabic=true&RadioRoot=false&WordString=$escaped_input&NX=903");
$array_of_results_ayalon = preg_match($ayalon_result, "/^/g");
echo "<pre>";
print_r($array_of_results_ayalon);
echo "</pre>";
die("done!");
}
$ayalon_result
calls a function that returns the content of a page with cURL.$ayalon_result
) there is a ^
sign followed by a few digits, and in the bottom of the returned page there is another ^
. The reason I do a preg_match
is because I want to make the 79156^
in the top of the returned page, for example, and the ^
in the bottom of the returned content disappear.The problem is that what is returned is just 0, and not an array with content. I guess it's something about the /^/g
that is not right, but I don't know how to fix it.
Please help me and tell me anything you didn't understand
Thank you!
Upvotes: 0
Views: 43
Reputation: 12079
PHP preg_match
takes the regular expression (regex) as the first argument, the variable to search for the pattern second, and an array to put the matches in third. The "^" is a regex operator indicating beginning of string, so to search for the character Caret, escape it with a backslash. And put parenthesis around the pattern to get all matches. So I think this is what you seek:
preg_match("/(\^\d+)/", $ayalon_result, $array_of_results_ayalon);
Swap what you have with this and see what you get.
Upvotes: 1