|
-
Jan 18th, 2011, 08:59 PM
#1
Thread Starter
Hyperactive Member
how to search by skipping equidistant letters
I want to search word within a string by equidistant letters pattern:
Example I want to search love within the x's at a skip of 3 letters or every 4th letter:
My logic is that first I need to explode the keyword:
Code:
str_split($keyword);
But I'm not sure afterward. But it's not splitting the into hebrew letters, rather a black diamond shape with a ?.
So far I have this:
PHP Code:
<?php for($tdid=0; $tdid < count($id); $tdid++){ $strText=stripslashes(mysql_escape_string($textData[$tdid])); include("../includefiles/vowelmarks.php"); for($i=0; $i<count($vm); $i++){ //echo $vm[$i]; $strText=str_replace($vm[$i], "", $strText); } $letters=str_split($strText); for($i=0; $i<count($letters); $i++){ if($letters[$i]!==" "){ if($i==0 or ($i%2)==22){ ?><tr><?php } //include("../includefiles/highlight_getBibleCode.php"); echo "<td id=\"regular[]\" style=\"font-size: 14px; direction: rtl; font-family:'SBL Hebrew';\">".$letters[$i]."</td>\n"; if(($i%2)==22){ ?></tr><?php } } } }
Last edited by gilgalbiblewhee; Jan 19th, 2011 at 12:38 AM.
-
Jan 19th, 2011, 03:44 PM
#2
Junior Member
Re: how to search by skipping equidistant letters
U can try something like this?
PHP Code:
<?php
$string = "xxxlxxxoxxxvxxxexxx";
$result = (string)NULL;
$done = false;
$string = substr($string,3);
$split = str_split($string);
$result .= $split[0];
while(!$done) {
$string = substr($string,4);
$split = str_split($string);
$result .= $split[0];
if(empty($string))
$done = true;
}
echo $result;
?>
-
Jan 19th, 2011, 11:37 PM
#3
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
 Originally Posted by Yearupie
U can try something like this?
PHP Code:
<?php $string = "xxxlxxxoxxxvxxxexxx"; $result = (string)NULL; $done = false;
$string = substr($string,3); $split = str_split($string); $result .= $split[0]; while(!$done) {
$string = substr($string,4); $split = str_split($string); $result .= $split[0]; if(empty($string)) $done = true; } echo $result; ?>
It works but I want the other way around where you search the word love and find out
- At what number of equdistant letters was it found
- highlight where the letters are found
Here's what I've done until now:
http://www.gbgrafix.com/thewheelofgo...e-code-search/
When you make your selections either type in a word in hebrew by using the keyboard which opens upon clicking in the one of the textareas on the left.
Or select the book and chapter and select a word and drag and drop in the textarea and click the same chapter to refresh it.
I've tried to figure out if every letter will be made bold and red which are found in the keyword but it didn't. It made some of the bold and red in the table.
the Keyword(s):
PHP Code:
echo "Words Searched For: <ol>"; $keyword_letters=Array(); $into_heb_letters=Array(); for($key=0; $key<count($COLORS); $key++){ if($textarea[$key]!=""){ echo "<li><span style=\"color:".$COLORS[$key]."; font-weight: bold;\">".$textarea[$key]."</span>"; $num = $key+1; if($textarea[$num]!=""){ echo " + "; } echo "</li>"; $strKeyword=$textarea[$key]; for($i=0; $i<count($alephbet); $i++){ $strKeyword=str_replace($alephbet[$i], $alphabet[$i], $strKeyword); } $strKeyword=str_replace(" ", "", $strKeyword); $into_letters=str_split($strKeyword); /* may be useful if willing to joing the keywors together for($i=0; $i<count($into_letters); $i++){ $keyword_letters[]=$into_letters[$i]; } */ for($eng=0; $eng<count($into_letters); $eng++){ for($heb=0; $heb<count($into_alephbet); $heb++){ if($alphabet[$heb]==$into_letters[$eng]){ $into_heb_letters[]=$into_alephbet[$heb]; } } } } } echo "</ol>";
I had to convert to english letters and reconvert them after the split();
So the letters in hebrew are in $into_heb_letters array without a problem.
No this is more complicated:
PHP Code:
$chap_letters= Array(); $chap_heb_letters= Array(); for($tdid=0; $tdid < count($id); $tdid++){ $strText=stripslashes(mysql_escape_string($textData[$tdid])); include("../includefiles/vowelmarks.php"); for($i=0; $i<count($vm); $i++){ $strText=str_replace($vm[$i], "", $strText); } for($i=0; $i<count($alephbet); $i++){ $strText=str_replace($alephbet[$i], $alphabet[$i], $strText); } $strText=str_replace(" ", "", $strText); $letters=str_split($strText); //print_r($letters); for($i=0; $i<count($letters); $i++){ //include("../includefiles/highlight_getBibleCode.php"); $chap_letters[]=$letters[$i]; } } for($i=0; $i<count($chap_letters); $i++){ $num=$i+1;//for the sake of the tr problem if($i==0){ echo "<tr>\n"; //echo "<td style=\"border: 1px solid black; font-size: 14px;\">".$num."</td>\n"; } $td="<td id=\"td_".$num."\" style=\"border: 1px solid black; font-size: 14px;".$hebrew_font."\">".$chap_letters[$i]."</td>\n"; for($j=0; $j<count($into_alephbet); $j++){ $td=str_replace(">".$alphabet[$j]."</", ">".$into_alephbet[$j]."</", $td); $chap_heb_letters[]=$into_alephbet[$j]; } for($k=0; $k<count($into_heb_letters); $k++){ if($chap_heb_letters[$i]==$into_heb_letters[$k]){ $td=str_replace("\">".$chap_heb_letters[$i]."</", " color: red;\">".$chap_heb_letters[$i]."</", $td); } } echo $td;
if($i!==0 && $num % $skiprow == 0){ echo "</tr>\n"; if($i<(count($letters)-1)){ echo "\n"; echo "<tr>\n"; //echo "<td style=\"border: 1px solid black; font-size: 14px;\">".$num."</td>\n"; } } }
I'll explain more about this in my next post.
Last edited by gilgalbiblewhee; Jan 19th, 2011 at 11:45 PM.
-
Jan 19th, 2011, 11:38 PM
#4
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
PHP Code:
for($j=0; $j<count($into_alephbet); $j++){
$td=str_replace(">".$alphabet[$j]."</", ">".$into_alephbet[$j]."</", $td);
$chap_heb_letters[]=$into_alephbet[$j];
}
for($k=0; $k<count($into_heb_letters); $k++){
if($chap_heb_letters[$i]==$into_heb_letters[$k]){
$td=str_replace("\">".$chap_heb_letters[$i]."</", " color: red;\">".$chap_heb_letters[$i]."</", $td);
}
}
echo $td;
$into_alephbet reconverts the english letters of the keyword into hebrew with str_replace();
$chap_heb_letters are all the hebrew letters in the chapter. My intention of writing the last for loop is that I wanted (to begin with) to see if all the letters of the keyword would be colored red in the grid.
But I intend to search if there's any match of equidistant hebrew letters of the keyword(s) in the given hebrew text.
-
Jan 21st, 2011, 12:51 AM
#5
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
 Originally Posted by Yearupie
U can try something like this?
PHP Code:
<?php $string = "xxxlxxxoxxxvxxxexxx"; $result = (string)NULL; $done = false;
$string = substr($string,3); $split = str_split($string); $result .= $split[0]; while(!$done) {
$string = substr($string,4); $split = str_split($string); $result .= $split[0]; if(empty($string)) $done = true; } echo $result; ?>
Let me rephrase this. So you set the number to 3 so that it would search the string at the skip of 3 letters.
What I'm looking for is that I want to search a $keyword like love within the string.
- My logic is that I have to break the string into an array of letters;
- break the $keyword into and array of letters
- create a for loop to search
- make the array of the count($keyword)*$i not exceed the count($string) else exit the loop
- here's where I find tricky: I need to match all the letters of the keyword to the letters of the string at the given equidistant letter sequence or $els which is a variable, or maybe use the $i from the for loop instead.
I have a question about the if statement:
can i bring in an array within the if brackets:
PHP Code:
if($kw[$k]==$str[$i] && $kw[$k]==$str[$i]...depending at the number of $key){ ...}
-
Jan 28th, 2011, 12:08 AM
#6
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
I can't figure it out so far:
PHP Code:
$els=mysql_escape_string($_GET["els"]);
$word=mysql_escape_string($_GET["word"]);
$string = "xxxlxxxoxxxvxxxexxxylyoyvye";
$split_string = str_split($string);
$split_word = str_split($word);
$searchmax=floor(count($split_string)/count($split_word));
for($j=0; $j<count($split_word); $j++){
for($i=0; $i<$searchmax; $i++){
if($split_word[$j]==$split_string[$i]){
$string=str_replace($split_string[$i], "<span style=\"color: red;\">".$split_string[$i]."</span>", $string);
$result=Array();
for($skip=0; $skip<$searchmax; $skip++){
if($split_word[$j+$skip]==$split_string[$i+$skip]){
$string=str_replace($split_string[$i+$skip], "<span style=\"color: red;\">".$split_string[$i+$skip]."</span>", $string);
}
$result[] = substr($string, $skip);
}
//print_r($result);
}
}
}
/*
$result = (string)NULL;
$done = false;
$string = substr($string,$els);
$result .= $split[0];
while(!$done) {
$string = substr($string,4);
$split = str_split($string);
$result .= $split[0];
if(empty($string))
$done = true;
}
*/
echo $string;
-
Jan 28th, 2011, 04:49 AM
#7
Re: how to search by skipping equidistant letters
Use a for loop to skip more than one character:
PHP Code:
$count = count($vm);
for($i=0; $i<$count; $i+=3){ echo $vm[$i]; }
-
Jan 28th, 2011, 05:19 AM
#8
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
strpos(); seems to be essential to know where to start.
PHP Code:
if($split_word[$j]==$split_string[$i]){
$findme=$split_word[$j];
$pos=strpos($string, $findme);
shows the first letter starts at position 3. But from that point it's not searching the 2-4th letters in the string.
PHP Code:
$els=mysql_escape_string($_GET["els"]);
$word=mysql_escape_string($_GET["word"]);
$string = "abclxxxoxxxvxxxexxxylyoyvye";
$split_string = str_split($string);
$split_word = str_split($word);
$searchmax=floor(count($split_string)/count($split_word));
for($j=0; $j<count($split_word); $j++){
for($i=0; $i<$searchmax; $i++){
if($split_word[$j]==$split_string[$i]){
$findme=$split_word[$j];
$pos=strpos($string, $findme);
echo $pos;
//$string=str_replace($split_string[$i], "<span style=\"color: red;\">".$split_string[$i]."</span>", $string);
$result=Array();
for($skip=0; $skip<$searchmax; $skip++){
$int = $pos+$skip;
if($split_word[$j+$skip]==$split_string[$int]){
$result[$int] = $split_string[$int];
//$string=str_replace($split_string[$int], "<span style=\"color: red;\">".$split_string[$int]."</span>", $string);
}
//$result[] = substr($string, $skip);
}
print_r($result);
}
}
}
/*
$result = (string)NULL;
$done = false;
$string = substr($string,$els);
$result .= $split[0];
while(!$done) {
$string = substr($string,4);
$split = str_split($string);
$result .= $split[0];
if(empty($string))
$done = true;
}
*/
echo $string;
-
Jan 29th, 2011, 01:49 AM
#9
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
Well half the problem seems to be solved:
PHP Code:
<input id="number" type="text" value="all" />
<input id="word" type="text" value="love" />
<a href="JavaScript: ext='?els='+document.getElementById('number').value+'&word='+document.getElementById('word').value; window.location=ext;">search this</a><br /><br />
<?php
$els=mysql_escape_string($_GET["els"]);
$word=mysql_escape_string($_GET["word"]);
$string = "abclxxxoxxxvxxxexxxylyoyvye";
$split_string = str_split($string);
$split_word = str_split($word);
$searchmax=floor(count($split_string)/count($split_word));
$word_pos=Array();
for($j=0; $j<count($split_word); $j++){
$word_pos[]=strpos($string, $split_word[$j]);
}
print_r($word_pos);
$j=0;
for($i=0; $i<count($split_string); $i++){
if($i==$word_pos[$j]){
$str.="<span style=\"color: red;\">".$split_string[$i]."</span>";
$j++;
}else{
$str.=$split_string[$i];
}
}
echo $str;
?>
This returns:
abc lxxx oxxx vxxx exxxylyoyvye
What I don't understand is why the other part is omitted. I would like that to be highlighted in another color like blue.
abc lxxx oxxx vxxx exxxy ly oy vy e
-
Feb 16th, 2011, 12:59 PM
#10
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
PHP Code:
$chars=$hebrew_chars; $string_split=$back_to_hebrew; $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; } } foreach ($instances as $i=>$instance){ $num=$i+1; $color=$COLORS[$i]; foreach($instance as $char){ $string_split[$char]="<td style=\"border: 1px solid black; font-weight: bold; color: ".$color.";\"><span id=\"span_".$num."\" style=\"display: block; width: 20px; height: 20px; font-weight: bold; font-size: 14px; text-align: center; background-color: ".$color."; color: white;\">".$string_split[$char]."</span></td>\n"; } } foreach($string_split as $i=>$part){ $num=$i+1; //echo 'The character at position ', $i, ' is "', $part, '"<br />'; if (strlen($part) <3){ $string_split[$i] = "<td style=\"border: 1px solid black;\"><span id=\"span_".$num."\" style=\"display: block; width: 20px; height: 20px; font-weight: bold; font-size: 14px; text-align: center; \">".$string_split[$i]."</span></td>"; } if ($i % $skiprow==0 && $i>0){ $string_split[$i] = "\n</tr>\n<tr>\n".$string_split[$i]; } }
echo implode("", $string_split);
I wonder where the changes should be made if an array of position numbers is already determined/figured out before hand?
I have a short example of the array:
PHP Code:
$set=(2705,2726,2747,2768,5,55,105,155,5,138,271,404)
of the word "turh". Since love is 4 characters long this mean the array can be divided into 3 sets of 4. There are some numbers which are repeated. I want the 3 sets to be colored differently.
I would figure that the $set is somehow similar to $instances except that $set is presenting all in one array and $instances is an array of arrays. If this is fixed it should work.
Last edited by gilgalbiblewhee; Feb 16th, 2011 at 01:20 PM.
-
Feb 17th, 2011, 12:50 AM
#11
Thread Starter
Hyperactive Member
Re: how to search by skipping equidistant letters
http://www.gbgrafix.com/thewheelofgo...=1&tochapter=2
column 6 from the right shows an empty blue td and a red td after that. It's supposed to be the same td. How can I fix that? It doesn't matter the color in this case because this shows the same letter is found in more than 1 combination.
PHP Code:
foreach ($instances as $i=>$instance){
$num=$i+1;
$color=$COLORS[$i];
foreach($instance as $char){
$string_split[$char]="<td style=\"border: 1px solid black; font-weight: bold; color: ".$color.";\"><span id=\"span_".$num."\" style=\"display: block; width: 20px; height: 20px; font-weight: bold; font-size: 14px; text-align: center; background-color: ".$color."; color: white;\">".$string_split[$char]."</span></td>\n";
}
}
foreach($string_split as $i=>$part){
$num=$i+1;
//echo 'The character at position ', $i, ' is "', $part, '"<br />';
if (strlen($part) <3){
$string_split[$i] = "<td style=\"border: 1px solid black;\"><span id=\"span_".$num."\" style=\"display: block; width: 20px; height: 20px; font-weight: bold; font-size: 14px; text-align: center; \">".$string_split[$i]."</span></td>";
}
if ($i % $skiprow==0 && $i>0){
$string_split[$i] = "\n</tr>\n<tr>\n".$string_split[$i];
}
}
echo implode("", $string_split);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|