Jump to content

[SOLVED] preg_match function error


dsaba

Recommended Posts

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

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

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[] = "&#1511;";
$hepattern[] = "&#1512;";
$hepattern[] = "&#1488;";
$hepattern[] = "&#1496;";
$hepattern[] = "&#1493;";
$hepattern[] = "&#1503;";
$hepattern[] = "&#1501;";
$hepattern[] = "&#1508;";
$hepattern[] = "&#1513;";
$hepattern[] = "&#1491;";
$hepattern[] = "&#1490;";
$hepattern[] = "&#1499;";
$hepattern[] = "&#1506;";
$hepattern[] = "&#1497;";
$hepattern[] = "&#1495;";
$hepattern[] = "&#1500;";
$hepattern[] = "&#1498;";
$hepattern[] = "&#1507;";
$hepattern[] = "&#1494;";
$hepattern[] = "&#1505;";
$hepattern[] = "&#1489;";
$hepattern[] = "&#1492;";
$hepattern[] = "&#1504;";
$hepattern[] = "&#1502;";
$hepattern[] = "&#1510;";
$hepattern[] = "&#1514;";
$hepattern[] = "&#1509;";

//$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, &#1495;&#1491;&#1513;&#1497;&#1501; &#1511;&#1489;&#1510;&#1497;&#1501;";
image_ready($string);


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.