How to search by skipping equidistant letters

And how does that answer my questions? :shifty:
You’ve gotta give me something here. I’d be happy to point you in the right direction but I’m not here to do your work for you.

I’m not sure where to put the tds. The ones with the style is easy but the ones without isn’t.

<input id="skiprow" type="text" value="all" />
<input id="word" type="text" value="love" />
<a href="JavaScript: ext='?skiprow='+document.getElementById('skiprow').value+'&word='+document.getElementById('word').value; window.location=ext;">search this</a><br /><br />
<?php
$skiprow=isset($_GET['skiprow']) ? $_GET['skiprow'] : '';
$word=isset($_GET['word']) ? $_GET['word'] : '';
$string="abclxxxoxxxvxxxexxxylyoyvye";

$COLORS=array('red', 'blue');
$string_split=str_split($string);
$chars=str_split($word);
$strlen=strlen($string);
$instances=array();
$continue=true;
$pos=0;
?>
<table style="float: left; direction: rtl; text-align: left; padding: 5px;">
    <tr>
<?php //<th style="border: 1px solid black;"></th>
for($i=0; $i<$skiprow; $i++){
	$num=$i+1;
	echo "<th style=\\"border: 1px solid black; font-size: 14px;\\">".$num."</th>\
";
}
?>
    </tr>
<?php
while($continue){
	$instance=array();
	foreach($chars as $char){
		if(($newPos=strpos($string, $char, $pos)) !== false){
			array_push($instance, $newPos);
			$string=substr_replace($string, '#', $newPos, 1);
			$pos=$newPos;
		}else{
			$continue=false;
			break;
		}
    }
	if (count($instance)==count($chars)){
		array_push($instances, $instance);
		$pos=0;
	}
}
foreach ($instances as $i=>$instance){
	$color=$COLORS[$i];
	foreach($instance as $char){
		$string_split[$char]="<td style=\\"color: ".$color.";\\">".$string_split[$char]."</td>";
	}
}
var_dump(implode('', $string_split));
?>
</table> 

any ideas?Don’t blame me. I’m trying to read your code and trying to figure out where to include it. I never use the for each loop to avoid confusion with the variables.

After


foreach ($instances as $i=>$instance){
    $color=$COLORS[$i];
    foreach($instance as $char){
        $string_split[$char]="<td style=\\"color: ".$color.";\\">".$string_split[$char]."</td>";
    }
} 

add


foreach($string_split as $i=>$part)
{
  if (strlen($part) == 1)
  {
    $string_split[$i] = '<td>' . $string_split[$i] . '</td>';
  }
}

Bit of a hack, but it works :slight_smile:

Ok but how about the tr tags?
If I want to change the $els which is the skipping of rows…the number of letters is 21. But if I want to make 15 letters per row…

foreach($string_split as $i=>$part){
	$num=$i+1;//for the sake of the tr problem
	if (strlen($part) == 1){
		if($i!==0 && $num % $skiprow == 0){
			$string_split[$i] = "</tr><tr><td style=\\"border: 1px solid black;\\">".$string_split[$i]."</td>\
";
		}else{
			$string_split[$i] = "<td style=\\"border: 1px solid black;\\">".$string_split[$i]."</td>\
";
		}
	}
}

This didn’t work.

The idea you had is okay, but it shouldn’t be in the if (strlen($part) == 1){
It needs to go outside that if statement :slight_smile:

Ok but for some reason the tr is either too early or 1 td or 2 tds too late depending if I add an 1 to the $num or take away 1…

foreach($string_split as $i=>$part){
	$num=$i+1;//for the sake of the tr problem
	if($i!==0 && $num % $skiprow == 0){
		$string_split[$i] = "</tr><tr><td style=\\"border: 1px solid black;\\">".$string_split[$i]."</td>\
";
	}else{	
		if(strlen($part) == 1){
			$string_split[$i] = "<td style=\\"border: 1px solid black;\\">".$string_split[$i]."</td>\
";
		}
	}
}

foreach($string_split as $i=>$part)
{
  if (strlen($part) == 1)
  {
    $string_split[$i] = '<td>' . $string_split[$i] . '</td>';
  }
	if ($i % $skiprow==0 && $i>0)
	{
		$string_split[$i] = '</tr><tr>' . $string_split[$i];
	}
}

echo '<table border=1><tr>', implode("\
", $string_split), '</tr></table>';

I didn’t read the whole thread, but it seems to me that the OP wants to find occurrences of words in the matrix of letters, be the occurrence in any orientation.
אני מכיר את התרגיל!‏

I suggest looking for the first occurrence of the first letter of the $needle, then the first occurrence of the second letter. See if there is a pattern, such as ($occurencePosition2-$occurencePosition1==$lengthOfLine) for vertical text, or ($occurencePosition2-$occurencePosition1==$lengthOfLine+1) for diagonal text. Then take it from there.

בהצלחה!‏
Good luck!

The dilemma is that in order to break down the text I have to convert the Hebrew letters into english to use the split function and then reconvert to hebrew. But this messes up your code as $string cannot be used and it give error.

<table style="float: left; direction: rtl; text-align: left; padding: 5px;">
    <tr>
<?php
for($i=0; $i<$skiprow; $i++){
	$num=$i+1;
	echo "<th style=\\"border: 1px solid black; font-size: 14px;\\">".$num."</th>\
";
}
?>
    </tr>
    <tr>
<?php
$text_of_this_chapter=implode("", $textData);
include("../includefiles/vowelmarks.php");
for($i=0; $i<count($vm); $i++){
	$text_of_this_chapter=str_replace($vm[$i], "", $text_of_this_chapter);
}
$text_of_this_chapter=str_replace(" ", "", $text_of_this_chapter);
for($i=0; $i<count($alephbet); $i++){
	$text_of_this_chapter=str_replace($alephbet[$i], $alphabet[$i], $text_of_this_chapter);
}
$into_letters=str_split($text_of_this_chapter);
for($i=0; $i<count($alphabet); $i++){
	$into_letters=str_replace($alphabet[$i], $alephbet[$i], $into_letters);
}

$skiprow=isset($_GET['skiprow']) ? $_GET['skiprow'] : '';
$word=isset($_GET['word']) ? $_GET['word'] : '';
$string=$text_of_this_chapter;//$string="abclxxxoxxxvxxleoyvye";

$COLORS=array('red', 'blue');
//$string_split=str_split($string);
$chars=str_split($word);
$strlen=strlen($string);
if($skiprow=="all"){
	$skiprow=$strlen;
}
$instances=array();
$continue=true;
$pos=0;

while($continue){
	$instance=array();
	foreach($chars as $char){
		if(($newPos=strpos($string, $char, $pos)) !== false){//this is where I get the error because of $string
			array_push($instance, $newPos);
			$string=substr_replace($string, '#', $newPos, 1);
			$pos=$newPos;
		}else{
			$continue=false;
			break;
		}
    }
	if(count($instance)==count($chars)){
		array_push($instances, $instance);
		$pos=0;
	}
}
foreach ($instances as $i=>$instance){
	$color=$COLORS[$i];
	foreach($instance as $char){
		$into_letters[$char]="<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-weight: bold; color: ".$color."; font-size: 14px;".$hebrew_font."\\">".$into_letters[$char]."</td>\
";
	}
}
foreach($into_letters as $i=>$part){
	if (strlen($part) == 1){
		$into_letters[$i] = "<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-size: 14px;".$hebrew_font."\\">".$into_letters[$i]."</td>";
	}
	if ($i % $skiprow==0 && $i>0){
		$into_letters[$i] = "</tr><tr>".$into_letters[$i];
	}
}

echo implode("", $into_letters);
?>
</tr>
</table>

Could you give an example string on which it breaks?

PS. Have a look at [fphp]strtr[/fphp] :slight_smile:

I use this:

<?php
$vm=array("&#1456;", "&#1468;", "&#1461;", "&#1460;", "&#1473;", "&#1430;", "&#1464;", "&#1457;", "&#1465;", "&#1461;", "&#1463;", "&#1473;", "&#1469;", "&#1462;", "&#1443;", "&#1425;", "&#1445;", "&#1445;", "&#1470;", "&#1431;", "&#1433;", "&#1433;", "&#1428;", "&#1428;", "&#1475;", "&#1470;", "&#1431;", "&#1433;", "&#1433;", "&#1428;", "&#1428;", "&#1447;", "&#1435;", "&#1448;", "&#1444;", " &#1472; ", "&#1474;", "&#1454;", "&#1426;", "&#1458;", "&#1458;", "&#1434;", "&#1434;", " &#1436;", "&#1440;", "&#1449;", "&#1436;", "&#1438;", "&#1429;", "&#1441;", "&#1467;", "&#1467;", "&#1459;", "&#1508;  &#1475;");
?>

I’ve included anything, (besides the vowel marks) such as the characters which note a separation of a paragraph dashes, double points used as periods…I will have to look into [fphp]strtr[/fphp]. But I don’t understand why if(($newPos=strpos($string, $char, $pos)) !== false){ says:

Warning: strpos() [function.strpos]: Empty delimiter

I think I know now $chars is related to $word and I haven’t changed this yet.

Ok that’s dealt with. But the html shows:

<tr>
&#1489;&#1512;&#1488;&#1513;&#1497;&#1514;&#1489;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1513;&#1502;&#1497;&#1502;&#1493;&#1488;&#1514;&#1492;&#1488;&#1512;&#1510;&#1493;&#1492;&#1488;&#1512;&#1510;&#1492;&#1497;&#1514;&#1492;&#1514;&#1492;&#1493;&#1493;&#1489;&#1492;&#1493;&#1493;&#1495;&#1513;&#1499;&#1506;&#1500;</tr><tr>&#1508;&#1504;&#1497;&#1514;&#1492;&#1493;&#1502;&#1493;&#1512;&#1493;&#1495;&#1488;&#1500;&#1492;&#1497;&#1502;&#1502;&#1512;&#1495;&#1508;&#1514;&#1506;&#1500;&#1508;&#1504;&#1497;&#1492;&#1502;&#1497;&#1502;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1492;&#1497;&#1488;&#1493;&#1512;&#1493;&#1497;&#1492;&#1497;</tr><tr>&#1488;&#1493;&#1512;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1488;&#1493;&#1512;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1489;&#1491;&#1500;&#1488;&#1500;&#1492;&#1497;&#1502;&#1489;&#1497;&#1504;&#1492;&#1488;&#1493;&#1512;&#1493;&#1489;&#1497;&#1504;&#1492;&#1495;&#1513;&#1499;&#1493;&#1497;</tr><tr>&#1511;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1500;&#1488;&#1493;&#1512;&#1497;&#1493;&#1502;&#1493;&#1500;&#1495;&#1513;&#1499;&#1511;&#1512;&#1488;&#1500;&#1497;&#1500;&#1492;&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1488;&#1495;&#1491;&#1493;&#1497;&#1488;</tr><tr>&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1492;&#1497;&#1512;&#1511;&#1497;&#1506;&#1489;&#1514;&#1493;&#1499;&#1492;&#1502;&#1497;&#1502;&#1493;&#1497;&#1492;&#1497;&#1502;&#1489;&#1491;&#1497;&#1500;&#1489;&#1497;&#1504;&#1502;&#1497;&#1502;&#1500;&#1502;&#1497;&#1502;&#1493;&#1497;&#1506;&#1513;&#1488;&#1500;&#1492;&#1497;&#1502;</tr><tr>&#1488;&#1514;&#1492;&#1512;&#1511;&#1497;&#1506;&#1493;&#1497;&#1489;&#1491;&#1500;&#1489;&#1497;&#1504;&#1492;&#1502;&#1497;&#1502;&#1488;&#1513;&#1512;&#1502;&#1514;&#1495;&#1514;&#1500;&#1512;&#1511;&#1497;&#1506;&#1493;&#1489;&#1497;&#1504;&#1492;&#1502;&#1497;&#1502;&#1488;&#1513;&#1512;&#1502;&#1506;&#1500;&#1500;&#1512;&#1511;&#1497;&#1506;</tr><tr>&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1497;&#1511;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1500;&#1512;&#1511;&#1497;&#1506;&#1513;&#1502;&#1497;&#1502;&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1513;&#1504;&#1497;&#1493;&#1497;&#1488;&#1502;&#1512;</tr><tr>&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1511;&#1493;&#1493;&#1492;&#1502;&#1497;&#1502;&#1502;&#1514;&#1495;&#1514;&#1492;&#1513;&#1502;&#1497;&#1502;&#1488;&#1500;&#1502;&#1511;&#1493;&#1502;&#1488;&#1495;&#1491;&#1493;&#1514;&#1512;&#1488;&#1492;&#1492;&#1497;&#1489;&#1513;&#1492;&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1497;&#1511;</tr><tr>&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1500;&#1497;&#1489;&#1513;&#1492;&#1488;&#1512;&#1510;&#1493;&#1500;&#1502;&#1511;&#1493;&#1492;&#1492;&#1502;&#1497;&#1502;&#1511;&#1512;&#1488;&#1497;&#1502;&#1497;&#1502;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1488;&#1502;</tr><tr>&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1514;&#1491;&#1513;&#1488;&#1492;&#1488;&#1512;&#1510;&#1491;&#1513;&#1488;&#1506;&#1513;&#1489;&#1502;&#1494;&#1512;&#1497;&#1506;&#1494;&#1512;&#1506;&#1506;&#1510;&#1508;&#1512;&#1497;&#1506;&#1513;&#1492;&#1508;&#1512;&#1497;&#1500;&#1502;&#1497;&#1504;&#1493;&#1488;&#1513;&#1512;&#1494;&#1512;&#1506;</tr><tr>&#1493;&#1489;&#1493;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1514;&#1493;&#1510;&#1488;&#1492;&#1488;&#1512;&#1510;&#1491;&#1513;&#1488;&#1506;&#1513;&#1489;&#1502;&#1494;&#1512;&#1497;&#1506;&#1494;&#1512;&#1506;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1493;&#1506;&#1510;&#1506;&#1513;&#1492;</tr><tr>&#1508;&#1512;&#1497;&#1488;&#1513;&#1512;&#1494;&#1512;&#1506;&#1493;&#1489;&#1493;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1513;</tr><tr>&#1500;&#1497;&#1513;&#1497;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1492;&#1497;&#1502;&#1488;&#1512;&#1514;&#1489;&#1512;&#1511;&#1497;&#1506;&#1492;&#1513;&#1502;&#1497;&#1502;&#1500;&#1492;&#1489;&#1491;&#1497;&#1500;&#1489;&#1497;&#1504;&#1492;&#1497;&#1493;&#1502;&#1493;&#1489;&#1497;&#1504;&#1492;&#1500;</tr><tr>&#1497;&#1500;&#1492;&#1493;&#1492;&#1497;&#1493;&#1500;&#1488;&#1514;&#1514;&#1493;&#1500;&#1502;&#1493;&#1506;&#1491;&#1497;&#1502;&#1493;&#1500;&#1497;&#1502;&#1497;&#1502;&#1493;&#1513;&#1504;&#1497;&#1502;&#1493;&#1492;&#1497;&#1493;&#1500;&#1502;&#1488;&#1493;&#1512;&#1514;&#1489;&#1512;&#1511;&#1497;&#1506;&#1492;&#1513;&#1502;&#1497;&#1502;</tr><tr>&#1500;&#1492;&#1488;&#1497;&#1512;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1497;&#1506;&#1513;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1513;&#1504;&#1497;&#1492;&#1502;&#1488;&#1512;&#1514;&#1492;&#1490;&#1491;&#1500;&#1497;&#1502;&#1488;&#1514;&#1492;&#1502;&#1488;&#1493;&#1512;&#1492;</tr><tr>&#1490;&#1491;&#1500;&#1500;&#1502;&#1502;&#1513;&#1500;&#1514;&#1492;&#1497;&#1493;&#1502;&#1493;&#1488;&#1514;&#1492;&#1502;&#1488;&#1493;&#1512;&#1492;&#1511;&#1496;&#1504;&#1500;&#1502;&#1502;&#1513;&#1500;&#1514;&#1492;&#1500;&#1497;&#1500;&#1492;&#1493;&#1488;&#1514;&#1492;&#1499;&#1493;&#1499;&#1489;&#1497;&#1502;&#1493;&#1497;&#1514;&#1504;</tr><tr>&#1488;&#1514;&#1502;&#1488;&#1500;&#1492;&#1497;&#1502;&#1489;&#1512;&#1511;&#1497;&#1506;&#1492;&#1513;&#1502;&#1497;&#1502;&#1500;&#1492;&#1488;&#1497;&#1512;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1500;&#1502;&#1513;&#1500;&#1489;&#1497;&#1493;&#1502;&#1493;&#1489;&#1500;&#1497;&#1500;&#1492;&#1493;&#1500;&#1492;&#1489;&#1491;&#1497;</tr><tr>&#1500;&#1489;&#1497;&#1504;&#1492;&#1488;&#1493;&#1512;&#1493;&#1489;&#1497;&#1504;&#1492;&#1495;&#1513;&#1499;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1512;&#1489;&#1497;</tr><tr>&#1506;&#1497;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1513;&#1512;&#1510;&#1493;&#1492;&#1502;&#1497;&#1502;&#1513;&#1512;&#1510;&#1504;&#1508;&#1513;&#1495;&#1497;&#1492;&#1493;&#1506;&#1493;&#1508;&#1497;&#1506;&#1493;&#1508;&#1508;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1506;&#1500;&#1508;&#1504;&#1497;</tr><tr>&#1512;&#1511;&#1497;&#1506;&#1492;&#1513;&#1502;&#1497;&#1502;&#1493;&#1497;&#1489;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1514;&#1504;&#1497;&#1504;&#1502;&#1492;&#1490;&#1491;&#1500;&#1497;&#1502;&#1493;&#1488;&#1514;&#1499;&#1500;&#1504;&#1508;&#1513;&#1492;&#1495;&#1497;&#1492;&#1492;&#1512;&#1502;&#1513;&#1514;</tr><tr>&#1488;&#1513;&#1512;&#1513;&#1512;&#1510;&#1493;&#1492;&#1502;&#1497;&#1502;&#1500;&#1502;&#1497;&#1504;&#1492;&#1502;&#1493;&#1488;&#1514;&#1499;&#1500;&#1506;&#1493;&#1508;&#1499;&#1504;&#1508;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;</tr><tr>&#1489;&#1512;&#1499;&#1488;&#1514;&#1502;&#1488;&#1500;&#1492;&#1497;&#1502;&#1500;&#1488;&#1502;&#1512;&#1508;&#1512;&#1493;&#1493;&#1512;&#1489;&#1493;&#1493;&#1502;&#1500;&#1488;&#1493;&#1488;&#1514;&#1492;&#1502;&#1497;&#1502;&#1489;&#1497;&#1502;&#1497;&#1502;&#1493;&#1492;&#1506;&#1493;&#1508;&#1497;&#1512;&#1489;&#1489;&#1488;&#1512;&#1510;</tr><tr>&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1495;&#1502;&#1497;&#1513;&#1497;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1514;&#1493;&#1510;&#1488;&#1492;&#1488;&#1512;&#1510;&#1504;&#1508;&#1513;&#1495;&#1497;&#1492;&#1500;&#1502;&#1497;&#1504;</tr><tr>&#1492;&#1489;&#1492;&#1502;&#1492;&#1493;&#1512;&#1502;&#1513;&#1493;&#1495;&#1497;&#1514;&#1493;&#1488;&#1512;&#1510;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1497;&#1506;&#1513;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1495;&#1497;&#1514;&#1492;&#1488;&#1512;&#1510;&#1500;&#1502;&#1497;&#1504;</tr><tr>&#1492;&#1493;&#1488;&#1514;&#1492;&#1489;&#1492;&#1502;&#1492;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1488;&#1514;&#1499;&#1500;&#1512;&#1502;&#1513;&#1492;&#1488;&#1491;&#1502;&#1492;&#1500;&#1502;&#1497;&#1504;&#1492;&#1493;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1488;</tr><tr>&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1504;&#1506;&#1513;&#1492;&#1488;&#1491;&#1502;&#1489;&#1510;&#1500;&#1502;&#1504;&#1493;&#1499;&#1491;&#1502;&#1493;&#1514;&#1504;&#1493;&#1493;&#1497;&#1512;&#1491;&#1493;&#1489;&#1491;&#1490;&#1514;&#1492;&#1497;&#1502;&#1493;&#1489;&#1506;&#1493;&#1508;&#1492;&#1513;&#1502;&#1497;&#1502;&#1493;</tr><tr>&#1489;&#1489;&#1492;&#1502;&#1492;&#1493;&#1489;&#1499;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1489;&#1499;&#1500;&#1492;&#1512;&#1502;&#1513;&#1492;&#1512;&#1502;&#1513;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1497;&#1489;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1488;&#1491;&#1502;&#1489;&#1510;&#1500;</tr><tr>&#1502;&#1493;&#1489;&#1510;&#1500;&#1502;&#1488;&#1500;&#1492;&#1497;&#1502;&#1489;&#1512;&#1488;&#1488;&#1514;&#1493;&#1494;&#1499;&#1512;&#1493;&#1504;&#1511;&#1489;&#1492;&#1489;&#1512;&#1488;&#1488;&#1514;&#1502;&#1493;&#1497;&#1489;&#1512;&#1499;&#1488;&#1514;&#1502;&#1488;&#1500;&#1492;&#1497;&#1502;&#1493;&#1497;&#1488;&#1502;&#1512;&#1500;</tr><tr>&#1492;&#1502;&#1488;&#1500;&#1492;&#1497;&#1502;&#1508;&#1512;&#1493;&#1493;&#1512;&#1489;&#1493;&#1493;&#1502;&#1500;&#1488;&#1493;&#1488;&#1514;&#1492;&#1488;&#1512;&#1510;&#1493;&#1499;&#1489;&#1513;&#1492;&#1493;&#1512;&#1491;&#1493;&#1489;&#1491;&#1490;&#1514;&#1492;&#1497;&#1502;&#1493;&#1489;&#1506;&#1493;&#1508;&#1492;&#1513;&#1502;&#1497;</tr><tr>&#1502;&#1493;&#1489;&#1499;&#1500;&#1495;&#1497;&#1492;&#1492;&#1512;&#1502;&#1513;&#1514;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1492;&#1504;&#1492;&#1504;&#1514;&#1514;&#1497;&#1500;&#1499;&#1502;&#1488;&#1514;&#1499;&#1500;&#1506;&#1513;&#1489;&#1494;&#1512;&#1506;&#1494;</tr><tr>&#1512;&#1506;&#1488;&#1513;&#1512;&#1506;&#1500;&#1508;&#1504;&#1497;&#1499;&#1500;&#1492;&#1488;&#1512;&#1510;&#1493;&#1488;&#1514;&#1499;&#1500;&#1492;&#1506;&#1510;&#1488;&#1513;&#1512;&#1489;&#1493;&#1508;&#1512;&#1497;&#1506;&#1510;&#1494;&#1512;&#1506;&#1494;&#1512;&#1506;&#1500;&#1499;&#1502;&#1497;&#1492;&#1497;&#1492;&#1500;&#1488;&#1499;</tr><tr>&#1500;&#1492;&#1493;&#1500;&#1499;&#1500;&#1495;&#1497;&#1514;&#1492;&#1488;&#1512;&#1510;&#1493;&#1500;&#1499;&#1500;&#1506;&#1493;&#1508;&#1492;&#1513;&#1502;&#1497;&#1502;&#1493;&#1500;&#1499;&#1500;&#1512;&#1493;&#1502;&#1513;&#1506;&#1500;&#1492;&#1488;&#1512;&#1510;&#1488;&#1513;&#1512;&#1489;&#1493;&#1504;&#1508;&#1513;&#1495;&#1497;&#1492;</tr><tr>&#1488;&#1514;&#1499;&#1500;&#1497;&#1512;&#1511;&#1506;&#1513;&#1489;&#1500;&#1488;&#1499;&#1500;&#1492;&#1493;&#1497;&#1492;&#1497;&#1499;&#1504;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1499;&#1500;&#1488;&#1513;&#1512;&#1506;&#1513;&#1492;&#1493;&#1492;&#1504;&#1492;&#1496;&#1493;&#1489;&#1502;&#1488;&#1491;</tr><tr>&#1493;&#1497;&#1492;&#1497;&#1506;&#1512;&#1489;&#1493;&#1497;&#1492;&#1497;&#1489;&#1511;&#1512;&#1497;&#1493;&#1502;&#1492;&#1513;&#1513;&#1497;</tr>

But supposed to break the string into characters and place them each character wrapped in td tags.

This is what I don’t understand about the foreach loop. What is => and I’ve tried reading at php.net but still don’t understand it. This is the reason why I can’t figure out how to fix the code. For some reason, the code below:

<?php

$text_of_this_chapter=implode("", $textData);
include("../includefiles/vowelmarks.php");
for($i=0; $i<count($vm); $i++){
	$text_of_this_chapter=str_replace($vm[$i], "", $text_of_this_chapter);
}
$text_of_this_chapter=str_replace(" ", "", $text_of_this_chapter);
for($i=0; $i<count($alephbet); $i++){
	$text_of_this_chapter=str_replace($alephbet[$i], $alphabet[$i], $text_of_this_chapter);
}
$into_letters=str_split($text_of_this_chapter);
for($i=0; $i<count($alphabet); $i++){
	$into_letters=str_replace($alphabet[$i], $alephbet[$i], $into_letters);
}

$skiprow=isset($_GET['skiprow']) ? $_GET['skiprow'] : '';
$word=isset($_GET['word']) ? $_GET['word'] : '';
$string=$text_of_this_chapter;//$string="abclxxxoxxxvxxleoyvye";

$COLORS=array('red', 'blue');
//$string_split=str_split($string);
$chars= $into_heb_letters;//str_split($word);
$strlen=strlen($string);
if($skiprow=="all"){
	$skiprow=$strlen;
}
$instances=array();
$continue=true;
$pos=0;

while($continue){
	$instance=array();
	foreach($chars as $char){
		if(($newPos=strpos($string, $char, $pos)) !== false){
			array_push($instance, $newPos);
			$string=substr_replace($string, '#', $newPos, 1);
			$pos=$newPos;
		}else{
			$continue=false;
			break;
		}
    }
	if(count($instance)==count($chars)){
		array_push($instances, $instance);
		$pos=0;
	}
}
?>
<table style="float: left; direction: rtl; text-align: left; padding: 5px;">
    <tr>
<?php
for($i=0; $i<$skiprow; $i++){
	$num=$i+1;
	echo "<th style=\\"border: 1px solid black; font-size: 14px;\\">".$num."</th>\
";
}
?>
    </tr>
    <tr>
<?php
$num=1;
foreach ($instances as $i=>$instance){
	$color=$COLORS[$i];
	foreach($instance as $char){
		$into_letters[$char]="<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-weight: bold; color: ".$color."; font-size: 14px;".$hebrew_font."\\">".$into_letters[$char]."</td>\
";
		$num++;
	}
}
foreach($into_letters as $i=>$part){
	if (strlen($part) == 1){
		$into_letters[$i] = "<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-size: 14px;".$hebrew_font."\\">".$into_letters[$i]."</td>";
		$num++;
	}
	if ($i % $skiprow==0 && $i>0){
		$into_letters[$i] = "</tr><tr>".$into_letters[$i];
	}
}
//print_r($into_letters);
echo implode("", $into_letters);
?>
</tr>
</table>

the last foreach loop:

foreach($into_letters as $i=>$part){
	if (strlen($part) == 1){
		$into_letters[$i] = "<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-size: 14px;".$hebrew_font."\\">".$into_letters[$i]."</td>";
		$num++;
	}
	if ($i % $skiprow==0 && $i>0){
		$into_letters[$i] = "</tr><tr>".$into_letters[$i];
	}
}

it’s neglecting the first if statement:

<th style="border: 1px solid black; font-size: 14px;">50</th>
    </tr>
    <tr>
&#1489;&#1512;&#1488;&#1513;&#1497;&#1514;&#1489;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1513;&#1502;&#1497;&#1502;&#1493;&#1488;&#1514;&#1492;&#1488;&#1512;&#1510;&#1493;&#1492;&#1488;&#1512;&#1510;&#1492;&#1497;&#1514;&#1492;&#1514;&#1492;&#1493;&#1493;&#1489;&#1492;&#1493;&#1493;&#1495;&#1513;&#1499;&#1506;&#1500;</tr><tr>&#1508;&#1504;&#1497;&#1514;&#1492;&#1493;&#1502;&#1493;&#1512;&#1493;&#1495;&#1488;&#1500;&#1492;&#1497;&#1502;&#1502;&#1512;&#1495;&#1508;&#1514;&#1506;&#1500;&#1508;&#1504;&#1497;&#1492;&#1502;&#1497;&#1502;&#1493;&#1497;&#1488;&#1502;&#1512;&#1488;&#1500;&#1492;&#1497;&#1502;&#1497;&#1492;&#1497;&#1488;&#1493;&#1512;&#1493;&#1497;&#1492;&#1497;</tr><tr>&#1488;&#1493;&#1512;&#1493;&#1497;&#1512;&#1488;&#1488;&#1500;&#1492;&#1497;&#1502;&#1488;&#1514;&#1492;&#1488;&#1493;&#1512;&#1499;&#1497;&#1496;&#1493;&#1489;&#1493;&#1497;&#1489;&#1491;&#1500;&#1488;&#1500;&#1492;&#1497;&#1502;&#1489;&#1497;&#1504;&#1492;&#1488;&#1493;&#1512;&#1493;&#1489;&#1497;&#1504;&#1492;&#1495;&#1513;&#1499;&#1493;&#1497;</tr>

Ah the alephbet it probably in UTF-8 or or UTF-16 right?

Try mb_strlen() instead of strlen()
If that doesn’t work try if (strlen($part) < 3)

As for the => in foreach, it splits the array in keys in values.
$a as $b=>$c means “loop over $a, setting $b as the key and $c as the value of each element”.

Since in this case $into_letters doesn’t have associative keys it simply has numeric keys.

Add this second line to see what’s going on:


foreach($into_letters as $i=>$part){
    echo 'The character at position ', $i, ' is "', $part, '"<br />';
    if (strlen($part) == 1){
        $into_letters[$i] = "<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-size: 14px;".$hebrew_font."\\">".$into_letters[$i]."</td>";
        $num++;
    }
    if ($i % $skiprow==0 && $i>0){
        $into_letters[$i] = "</tr><tr>".$into_letters[$i];
    }
} 

utf-8

the character at position 0 is “ב”
the character at position 1 is “ר”
the character at position 2 is “א”
the character at position 3 is “ש”
the character at position 4 is “י”
the character at position 5 is “ת”

I don’t think it recognizes $instance:

foreach ($instances as $i=>$instance){echo 'The character at position ', $i, ' is "', $instance, '"<br />';
	$color=$COLORS[$i];
	foreach($instance as $char){
		$into_letters[$char]="<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-weight: bold; color: ".$color."; font-size: 14px;".$hebrew_font."\\">".$into_letters[$char]."</td>\
";
		$num++;
	}
}

Because it’s not emboldening the letters found.

foreach ($instances as $i=>$instance){
	echo 'The character at position ', $i, ' is "', $instance, '"<br />';
	$color=$COLORS[$i];
	foreach($instance as $char){
		$into_letters[$char]="<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-weight: bold; color: ".$color."; font-size: 14px;".$hebrew_font."\\">".$into_letters[$char]."</td>\
";
		$num++;
	}
}
print_r($instance);
print_r($instances);

both show empty arrays.

I think I found out the reason…that $string in the while loop:

$skiprow=isset($_GET['skiprow']) ? $_GET['skiprow'] : '';
$word=isset($_GET['word']) ? $_GET['word'] : '';
$string=$text_of_this_chapter;//$string="abclxxxoxxxvxxleoyvye";

$COLORS=array('red', 'blue');
//$string_split=str_split($string);
$chars= $into_heb_letters;//str_split($word);
$strlen=strlen($string);
if($skiprow=="all"){
	$skiprow=$strlen;
}
$instances=array();
$continue=true;
$pos=0;

while($continue){
	$instance=array();
	foreach($chars as $char){
		if(($newPos=strpos($string, $char, $pos)) !== false){
			array_push($instance, $newPos);
			$string=substr_replace($string, '#', $newPos, 1);
			$pos=$newPos;
		}else{
			$continue=false;
			break;
		}
    }
	if(count($instance)==count($chars)){
		array_push($instances, $instance); //adds to the array
		$pos=0;
	}
	echo "string--> ".$string." <--string";
}

shows english letters instead of hebrew, because I transposed it, because otherwise str_split would result in diamonds with ? in them.

I’m trying to plug my variables properly to make it work in this while loop:

$str_into_heb_letters=str_split($text_of_this_chapter);
for($i=0; $i<count($alphabet); $i++){
	$str_into_heb_letters=str_replace($alphabet[$i], $alephbet[$i], $str_into_heb_letters);
}
...
$string=implode("", $str_into_heb_letters);

I imploded to use that in:

while($continue){
    $instance=array();
    foreach($chars as $char){
        if(($newPos=strpos($string, $char, $pos)) !== false){
            array_push($instance, $newPos);
            $string=substr_replace($string, '#', $newPos, 1);
            $pos=$newPos;
        }else{
            $continue=false;
            break;
        }
    }
    if(count($instance)==count($chars)){
        array_push($instances, $instance);
        $pos=0;
    }
}

But something went wrong and the page is showing blank tds.
What is the $continue doing?

I think I’m going to give up at this point. Some things I fixed but it’s not doing what I intend it to do:

<?php
$text_of_this_chapter=implode("", $textData);
include("../includefiles/vowelmarks.php");
for($i=0; $i<count($vm); $i++){
	$text_of_this_chapter=str_replace($vm[$i], "", $text_of_this_chapter);
}
$text_of_this_chapter=str_replace(" ", "", $text_of_this_chapter);
for($i=0; $i<count($alephbet); $i++){
	$text_of_this_chapter=str_replace($alephbet[$i], $alphabet[$i], $text_of_this_chapter);
}
$str_into_heb_letters=str_split($text_of_this_chapter);
for($i=0; $i<count($alphabet); $i++){
	$str_into_heb_letters=str_replace($alphabet[$i], $alephbet[$i], $str_into_heb_letters);
}
//print_r($str_into_heb_letters);
$skiprow=isset($_GET['skiprow']) ? $_GET['skiprow'] : '';
$string=implode("", $str_into_heb_letters);
$COLORS=array('red', 'blue');
//$string_split=str_split($string);
$chars= $into_heb_letters;//renamed the array
$strlen=strlen($string);
if($skiprow=="all"){
	$skiprow=$strlen;
}
$instances=array();
$continue=true;
$pos=0;

while($continue){
	$instance=array();
	foreach($chars as $char){
		if(($newPos=strpos($string, $char, $pos)) !== false){
			array_push($instance, $newPos);
			$string=substr_replace($string, '#', $newPos, 1);
			$pos=$newPos;
		}else{
			$continue=false;
			break;
		}
    }
	if(count($instance)==count($chars)){
		array_push($instances, $instance); //adds to the array
		$pos=0;
	}
}
//echo count($instance)." and ".count($chars);
?>
<table style="float: left; direction: rtl; text-align: left; padding: 5px;">
    <tr>
<?php
for($i=0; $i<$skiprow; $i++){
	$num=$i+1;
	echo "<th style=\\"border: 1px solid black; font-size: 14px;\\">".$num."</th>\
";
}
?>
    </tr>
    <tr>
<?php
$num=1;
foreach($instances as $i=>$instance){
	//echo 'The character at position ', $i, ' is "', $instance, '"<br />';
	$color=$COLORS[$i];
	foreach($instance as $char){
		$str_into_heb_letters[$char]="<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-weight: bold; color: ".$color."; font-size: 14px;".$hebrew_font."\\">".$str_into_heb_letters[$char]."</td>\
";
		$num++;
	}
}

foreach($str_into_heb_letters as $i=>$part){
	//echo 'The character at position ', $i, ' is "', $part, '"<br />';
	if (strlen($part)<3){
		$str_into_heb_letters[$i] = "\
<td id=\\"td_".$num."\\" style=\\"border: 1px solid black; font-size: 14px;".$hebrew_font."\\">".$str_into_heb_letters[$i]."</td>";
		$num++;
	}
	if ($i % $skiprow==0 && $i>0){
		$str_into_heb_letters[$i] = "\
</tr>\
<tr>".$str_into_heb_letters[$i];
	}
} 
//print_r($into_letters);
echo implode("", $str_into_heb_letters);
?>
</tr>
</table>

Words Searched For:

  1. תורה

And what do I get?

I put the table in txt mode zipped because it was too big. But my point is that it was making bold and coloring words that are not part of the search at all.