SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 87
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    xxxlxxxoxxxvxxxexxx
    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==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
                
    }
            }
        }
    }
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unless I'm misunderstanding something, why can't you just explode the string using 'xxx' as the delimeter and then concatenate every 2nd element of the returned array, if it is a letter, to get the embedded word?

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dantel View Post
    unless I'm misunderstanding something, why can't you just explode the string using 'xxx' as the delimeter and then concatenate every 2nd element of the returned array, if it is a letter, to get the embedded word?
    I want to conduct a search of how many of the keyword can you find in:
    xxxlxxxoxxxvxxleoxvxex
    if $keyword=love?
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gilgalbiblewheel View Post
    I want to conduct a search of how many of the keyword can you find in:

    if $keyword=love?
    Now you have changed the criteria in which words can be embedded in the x's. In your op the letters were spaces a constant 3 x's apart and your thread title says the letters are equidistant.

    Now you are showing the embedded words can overlap each other and that the letters don't have to be equidistant apart. There's too much uncertainty in your posted criteria so I think I'll leave this one alone.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2006
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This looks like code to do a crossword puzzle. To verify that a word doesn't appear twice in a string. But you have letters between your letters? Maybe you can instead explode the search term into individual letters and then search your xxxlxxxoxxxvxxleoxvxex string for each time an l appears if an o appears after then check if a v appears after, etc...

    If not than I misunderstood this problem.
    Please...Never describe anything to me using foo and bar.

  6. #6
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    gilgalbiblewheel, can you give some real examples of the strings you want to work with, values to look for, demonstrations of what you want to find?
    Salathe
    Software Developer and PHP Manual Author.

  7. #7
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by prince_mallow View Post
    This looks like code to do a crossword puzzle. To verify that a word doesn't appear twice in a string. But you have letters between your letters? Maybe you can instead explode the search term into individual letters and then search your xxxlxxxoxxxvxxleoxvxex string for each time an l appears if an o appears after then check if a v appears after, etc...

    If not than I misunderstood this problem.
    that's right like a crossword puzzle. I pretty much figured it out, that the text given is split up into a huge array of letters. And the search ought to look for two letters at a certain number apart and try to match another latter with the same number otherwise it should skip or exit and continue with a new search.
    Compare bible texts (and other tools):
    TheWheelofGod

  8. #8
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    gilgalbiblewheel, can you give some real examples of the strings you want to work with, values to look for, demonstrations of what you want to find?
    Take a look at my website:
    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):
    Code PHP:
    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:
    Code PHP:
    $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.
    Compare bible texts (and other tools):
    TheWheelofGod

  9. #9
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
        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.
    Compare bible texts (and other tools):
    TheWheelofGod

  10. #10
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I'm looking for is that I want to search a $keyword like love within the string.

    1. My logic is that I have to break the string into an array of letters;
    2. break the $keyword into and array of letters
    3. create a for loop to search
    4. make the array of the count($keyword)*$i not exceed the count($string) else exit the loop
    5. 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){
    ...} 
    Compare bible texts (and other tools):
    TheWheelofGod

  11. #11
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't figure it out so far:
    Code PHP:
    $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;
    Compare bible texts (and other tools):
    TheWheelofGod

  12. #12
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strpos(); seems to be essential to know where to start.
    Code PHP:
    		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.
    Code 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));
     
    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;
    Compare bible texts (and other tools):
    TheWheelofGod

  13. #13
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well half the problem seems to be solved:
    Code PHP:
    <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:
    abclxxxoxxxvxxxexxxylyoyvye
    What I don't understand is why the other part is omitted. I would like that to be highlighted in another color like blue.
    abclxxxoxxxvxxxexxxylyoyvye
    Compare bible texts (and other tools):
    TheWheelofGod

  14. #14
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Your function doesn't work. Sure it seems to be working because it colors "love" in the string, but if you only have L, O and V in the string (no E) it will also color LOV, and that's not supposed to happen. It should color the whole word or nothing at all.

    This works:
    PHP Code:
    <?php
    $els
    =isset($_GET['els']) ? $_GET['els'] : '';
    $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;

    while (
    $continue)
    {
        
    $instance=array();
        foreach(
    $chars as $char)
        {
            if ((
    $newPos=strpos($string$char$pos)) !== false)
            {
                
    array_push($instance$newPos);
                
    $string=substr_replace($string'#'$newPos1);
                
    $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]='<strong style="color: '.$color.';">'.$string_split[$char].'</strong>';
        }
    }

    var_dump(implode(''$string_split));
    For "abclxxxoxxxvxxxexxxylyoyvye" it outputs abclxxxoxxxvxxxexxxylyoyvye

    It can also detect interwoven words.
    For example for "xxlxlxxoxoxvxxvxexxe" it outputs xxlxlxxoxoxvxxvxexxe

    Please take a look at the code and see if you can follow what it does. If there is anything you can't quite follow don't hesitate to ask!
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  15. #15
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Your function doesn't work. Sure it seems to be working because it colors "love" in the string, but if you only have L, O and V in the string (no E) it will also color LOV, and that's not supposed to happen. It should color the whole word or nothing at all.

    This works:
    PHP Code:
    <?php
    $els
    =isset($_GET['els']) ? $_GET['els'] : '';
    $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;

    while (
    $continue)
    {
        
    $instance=array();
        foreach(
    $chars as $char)
        {
            if ((
    $newPos=strpos($string$char$pos)) !== false)
            {
                
    array_push($instance$newPos);
                
    $string=substr_replace($string'#'$newPos1);
                
    $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]='<strong style="color: '.$color.';">'.$string_split[$char].'</strong>';
        }
    }

    var_dump(implode(''$string_split));
    For "abclxxxoxxxvxxxexxxylyoyvye" it outputs abclxxxoxxxvxxxexxxylyoyvye

    It can also detect interwoven words.
    For example for "xxlxlxxoxoxvxxvxexxe" it outputs xxlxlxxoxoxvxxvxexxe

    Please take a look at the code and see if you can follow what it does. If there is anything you can't quite follow don't hesitate to ask! :)
    Warning: strpos() [function.strpos]: Empty delimiter in \examples\mybcode3.php on line 28
    There's an error
    Compare bible texts (and other tools):
    TheWheelofGod

  16. #16
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by gilgalbiblewheel View Post
    There's an error
    Did you provide $_GET['word'] ? If not you do indeed get that error.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  17. #17
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Did you provide $_GET['word'] ? If not you do indeed get that error.
    That's right I forgot about that. Thanks!
    Compare bible texts (and other tools):
    TheWheelofGod

  18. #18
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where can I put the <td> tags for the non-highlighted letters? The $els should determine the amount of tds per tr.
    Compare bible texts (and other tools):
    TheWheelofGod

  19. #19
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by gilgalbiblewheel View Post
    where can I put the <td> tags for the non-highlighted letters? The $els should determine the amount of tds per tr.
    I don't follow. How do you want <td>s in here? What have you tried yourself? Do you understand the code I posted?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  20. #20
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    I don't follow. How do you want <td>s in here? What have you tried yourself? Do you understand the code I posted?
    http://www.gbgrafix.com/thewheelofgo...e-code-search/
    Except that I intend to replace your code instead of this.
    Compare bible texts (and other tools):
    TheWheelofGod

  21. #21
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by gilgalbiblewheel View Post
    http://www.gbgrafix.com/thewheelofgo...e-code-search/
    Except that I intend to replace your code instead of this.
    And how does that answer my questions?
    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.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  22. #22
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    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.
    Code PHP:
    <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>\n";
    }
    ?>
        </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>
    Compare bible texts (and other tools):
    TheWheelofGod

  23. #23
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Compare bible texts (and other tools):
    TheWheelofGod

  24. #24
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    After

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

    add

    PHP Code:
    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
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  25. #25
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    After

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

    add

    PHP Code:
    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 :)
    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...
    Code PHP:
    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>\n";
    		}else{
    			$string_split[$i] = "<td style=\"border: 1px solid black;\">".$string_split[$i]."</td>\n";
    		}
    	}
    }
    This didn't work.
    Compare bible texts (and other tools):
    TheWheelofGod


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •