Hagaymosko
Hagaymosko

Reputation: 51

PHP preg_match trouble

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!");
}

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

Answers (1)

bloodyKnuckles
bloodyKnuckles

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

Related Questions