dsaba Posted March 26, 2007 Share Posted March 26, 2007 I get this error: Warning: preg_match() expects parameter 1 to be string, array i'm using the preg_match function like this: preg_match($hepattern, $word); here's the $hepattern array: $hepattern[] = "ק"; $hepattern[] = "ר"; $hepattern[] = "א"; $hepattern[] = "ט"; $hepattern[] = "ו"; $hepattern[] = "ן"; $hepattern[] = "ם"; $hepattern[] = "פ"; $hepattern[] = "ש"; $hepattern[] = "ד"; $hepattern[] = "ג"; $hepattern[] = "כ"; $hepattern[] = "ע"; $hepattern[] = "י"; $hepattern[] = "ח"; $hepattern[] = "ל"; $hepattern[] = "ך"; $hepattern[] = "ף"; $hepattern[] = "ז"; $hepattern[] = "ס"; $hepattern[] = "ב"; $hepattern[] = "ה"; $hepattern[] = "נ"; $hepattern[] = "מ"; $hepattern[] = "צ"; $hepattern[] = "ת"; $hepattern[] = "ץ"; What am I doing wrong? -thanks Quote Link to comment Share on other sites More sharing options...
dsaba Posted March 26, 2007 Author Share Posted March 26, 2007 here is the full script if you need it <?php //-------REVERSE UTF8 STRING FUNCTION------------------ function utf8_strrev($str){ preg_match_all('/./us', $str, $ar); return join('',array_reverse($ar[0])); } //------END REVERSE UTF8 STRING FUNCTION--------------- //-------------------------------------IMAGE_READY FUNCTION------------------------------------------------------------- function image_ready($string) { //hebrew character pattern $hepattern[] = "ק"; $hepattern[] = "ר"; $hepattern[] = "א"; $hepattern[] = "ט"; $hepattern[] = "ו"; $hepattern[] = "ן"; $hepattern[] = "ם"; $hepattern[] = "פ"; $hepattern[] = "ש"; $hepattern[] = "ד"; $hepattern[] = "ג"; $hepattern[] = "כ"; $hepattern[] = "ע"; $hepattern[] = "י"; $hepattern[] = "ח"; $hepattern[] = "ל"; $hepattern[] = "ך"; $hepattern[] = "ף"; $hepattern[] = "ז"; $hepattern[] = "ס"; $hepattern[] = "ב"; $hepattern[] = "ה"; $hepattern[] = "נ"; $hepattern[] = "מ"; $hepattern[] = "צ"; $hepattern[] = "ת"; $hepattern[] = "ץ"; //$stringarray = preg_split("/[\s,]+/", $string); $stringarray = explode(" ", $string); foreach ($stringarray as $key => $value) { $word = $value; if ((preg_match($hepattern, $word)) == TRUE) { $newarray[] = utf8_strrev($word); } else { $newarray[] = $word; } //end foreach statement } $imagestring = implode(" ", $newarray); //end function } //----------------------------------------END IMAGE_READY FUNCTION----------------------------------------------------------- $string = "this is english, חדשים קבצים"; image_ready($string); ?> Quote Link to comment Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 Read up on http://www.php.net/preg_match . Quote Link to comment Share on other sites More sharing options...
dsaba Posted March 26, 2007 Author Share Posted March 26, 2007 Read up on http://www.php.net/preg_match . I went there first, that's how I made up function syntax in the first place could you answer my question if there is somethign wrong with the way I used it in the code i posted above? Quote Link to comment Share on other sites More sharing options...
rcorlew Posted March 27, 2007 Share Posted March 27, 2007 You need an output string even if you don't use it. Here is the code for you to use: <?php //-------REVERSE UTF8 STRING FUNCTION------------------ function utf8_strrev($str){ preg_match_all('/./us', $str, $ar); return join('',array_reverse($ar[0])); } //------END REVERSE UTF8 STRING FUNCTION--------------- //-------------------------------------IMAGE_READY FUNCTION------------------------------------------------------------- function image_ready($string) { //hebrew character pattern $hepattern[] = "ק"; $hepattern[] = "ר"; $hepattern[] = "א"; $hepattern[] = "ט"; $hepattern[] = "ו"; $hepattern[] = "ן"; $hepattern[] = "ם"; $hepattern[] = "פ"; $hepattern[] = "ש"; $hepattern[] = "ד"; $hepattern[] = "ג"; $hepattern[] = "כ"; $hepattern[] = "ע"; $hepattern[] = "י"; $hepattern[] = "ח"; $hepattern[] = "ל"; $hepattern[] = "ך"; $hepattern[] = "ף"; $hepattern[] = "ז"; $hepattern[] = "ס"; $hepattern[] = "ב"; $hepattern[] = "ה"; $hepattern[] = "נ"; $hepattern[] = "מ"; $hepattern[] = "צ"; $hepattern[] = "ת"; $hepattern[] = "ץ"; //$stringarray = preg_split("/[\s,]+/", $string); $stringarray = explode(" ", $string); foreach ($stringarray as $key => $value) { $word = $value; //new stuff below if ((preg_match($hepattern, $useless, $word)) == TRUE) { // new -- added output string $useless $newarray[] = utf8_strrev($word); //nothing new } //all old stuff below else { $newarray[] = $word; } //end foreach statement } $imagestring = implode(" ", $newarray); //end function } //----------------------------------------END IMAGE_READY FUNCTION----------------------------------------------------------- $string = "this is english, חדשים קבצים"; image_ready($string); ?> Quote Link to comment Share on other sites More sharing options...
dsaba Posted March 27, 2007 Author Share Posted March 27, 2007 thanks for the reply arrow! i've been working on this all day, i did find another method to do it, but I will also try this out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.