1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Why is the last array returning null?

Discussion in 'PHP' started by gilgalbiblewheel, Jun 30, 2018.

  1. #1
    For some reason that last array is returning NULL. It's supposed to be returning "H11":
    
    <?php
    $all_description_blb = array();
    $all_etymologyStrongs = array();
    
    $string1 = "";
    $string2 = "";
    $string3 = "";
    $string4 = "";
    $blbdescription = "<span style=\"color: red; font-weight: bold;\"> The same as <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H9&amp;t=KJV\" title=\"English: lost thing, that which was lost\"><span class=\"Hb\">אֲבֵדָה</span> (H9)</a>, incorrectly written for <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H11&amp;t=KJV\" title=\"English: destruction\"><span class=\"Hb\">אֲבַדּוֹן</span> (H11)</a> </span>";
    
    
    
    preg_match_all("#<\b(a)\b[^>]*>(.*?)</\b(a)\b>#si", $blbdescription, $stripatag, PREG_SET_ORDER);
    
    array_push($all_description_blb, $blbdescription);
    
    $string1 .=  "-----<br /><br />\n";
    $string1 .=  "stripatag <pre style=\"color: red; font-weight: bold;\">";
    //var_dump($stripatag);
    $string2 .=  "</pre> ";
    $string2 .=  "<br /><br />\n";
    $string3 .=  "-----<br /><br />\n";
    $string3 .=  "stripbracketsforetymstrongsarray <pre style=\"color: red; font-weight: bold;\">";
    $string4 .=  "-----<br /><br />\n";
    $string4 .=  "stripatag [0][2] <span style=\"color: green; font-weight: bold;\">".$stripatag[0][2]."</span><br /><br />\n";
    $string4 .=  "stripatag [1][2] <span style=\"color: green; font-weight: bold;\">".$stripatag[1][2]."</span><br /><br />\n";//Notice: Undefined offset: 1 in C:\xampp\htdocs\biblewheel\update_outline\index.php on line 228
    $string2 .=  "---------------------------------------------------------------<br /><br />\n";
    
    
    for($a=0;$a<count($stripatag);$a++){
       preg_match_all("/.*\(([^)]*)\)/", $stripatag[$a][2], $stripbracketsforetymstrongsarray, PREG_SET_ORDER);
       $etymologyStrongs = $stripbracketsforetymstrongsarray[$a][1];//$href[$a][2] or $href3array[$a][2]?
       array_push($all_etymologyStrongs, $etymologyStrongs);
    }
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    echo $string1;
    var_dump($stripatag);
    echo $string2;
    
    echo $string3;
    var_dump($all_etymologyStrongs);
    echo $string2;
    
    echo $string4;
    ?>
    </body>
    </html>
    
    
    PHP:

     
    Last edited: Jun 30, 2018
    gilgalbiblewheel, Jun 30, 2018 IP
  2. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #2
    It seems like there should be
    $etymologyStrongs = $stripbracketsforetymstrongsarray[0][1];//$href[$a][2] or $href3array[$a][2]?
    PHP:
    instead of
    $etymologyStrongs = $stripbracketsforetymstrongsarray[$a][1];//$href[$a][2] or $href3array[$a][2]?
    PHP:
     
    Nei, Jun 30, 2018 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    This comes close to what I'm looking for but there are still notices:
    
    <?php
    $all_description_blb = array();
    $all_etymologyStrongs = array();
    
    $string1 = "";
    $string2 = "";
    $string3 = "";
    $string4 = "";
    $blbdescription = "<span style=\"color: red; font-weight: bold;\"> The same as <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H9&amp;t=KJV\" title=\"English: lost thing, that which was lost\"><span class=\"Hb\">אֲבֵדָה</span> (H9)</a>, incorrectly written for <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H11&amp;t=KJV\" title=\"English: destruction\"><span class=\"Hb\">אֲבַדּוֹן</span> (H11)</a> </span>";
    
    preg_match_all("#<\b(a)\b[^>]*>(.*?)</\b(a)\b>#si", $blbdescription, $stripatag, PREG_SET_ORDER);
    
    array_push($all_description_blb, $blbdescription);
    
    $string1 .=  "-----<br /><br />\n";
    $string1 .=  "stripatag <pre style=\"color: red; font-weight: bold;\">";
    //var_dump($stripatag);
    $string2 .=  "</pre> ";
    $string2 .=  "<br /><br />\n";
    $string3 .=  "-----<br /><br />\n";
    $string3 .=  "stripbracketsforetymstrongsarray <pre style=\"color: red; font-weight: bold;\">";
    $string4 .=  "-----<br /><br />\n";
    $string4 .=  "stripatag [0][2] <span style=\"color: green; font-weight: bold;\">".$stripatag[0][2]."</span><br /><br />\n";
    $string4 .=  "stripatag [1][2] <span style=\"color: green; font-weight: bold;\">".$stripatag[1][2]."</span><br /><br />\n";//Notice: Undefined offset: 1 in ...\index.php on line 228
    $string2 .=  "---------------------------------------------------------------<br /><br />\n";
    
    
    
    for($a=0;$a<count($stripatag);$a++){
       preg_match_all("/.*\(([^)]*)\)/", $stripatag[$a][2], $stripbracketsforetymstrongsarray, PREG_SET_ORDER);
       for($b=0;$b<count($stripatag[$a]);$b++){
         $etymologyStrongs = $stripbracketsforetymstrongsarray[$b][1];//Line 34 is this       $href[$a][2] or $href3array[$a][2]?
         array_push($all_etymologyStrongs, $etymologyStrongs);
       }
    }
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    echo $string1;
    var_dump($stripatag);
    echo $string2;
    
    echo $string3;
    var_dump($all_etymologyStrongs);
    echo $string2;
    
    echo $string4;
    ?>
    </body>
    </html>
    
    
    PHP:
    But is it possible of doing in one for loop instead of 2: $a and $b?
    It shows the following:
     
    gilgalbiblewheel, Jun 30, 2018 IP
  4. Benanamen

    Benanamen Greenhorn

    Messages:
    22
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    20
    #4
    What is the real problem you are trying to solve? I dont mean your attempt at solving it.
     
    Benanamen, Jul 1, 2018 IP
  5. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    i want to grab the numbers with H or G next to them.
     
    gilgalbiblewheel, Jul 1, 2018 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    This works:

    http://sandbox.onlinephpfunctions.com/code/0ce2fc04eca2d03f6b684a2dd84a1d8918c97e5b

    
    <?php
    $blbdescription = "<span style=\"color: red; font-weight: bold;\"> (G4) The same as <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H9&amp;t=KJV\" title=\"English: lost thing, that which was lost\"><span class=\"Hb\">אֲבֵדָה</span> (H9)</a>, incorrectly written for <a class=\"nowrap\" href=\"lexicon.cfm?strongs=H11&amp;t=KJV\" title=\"English: destruction\"><span class=\"Hb\">אֲבַדּוֹן</span> (H11)</a> </span>";
    
    preg_match_all('/\([H|G]{1}([0-9]+)\)/', $blbdescription, $res);
    print_r($res);
    
    
    PHP:
    Also avoid variable names that are soooooooo long.
     
    ThePHPMaster, Jul 1, 2018 IP
    Nei likes this.
  7. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #7
    Yes this does open perhaps an easier way for the php coding. I might need to make big changes in my coding. I know what you mean about the long variable names however months down the road when I look back at the codes I want to be able to recognize them.

    Is it a good thing to add a tag attributes in a db table? or is there a better way to break them down and most importantly add the titles in the a tags in a separate column?

    Also is there a way to strip the brackets but leave the letters with the numbers:

    Instead of:

     
    Last edited: Jul 1, 2018
    gilgalbiblewheel, Jul 1, 2018 IP
  8. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #8
    Update the regular expression to include the letter part of the match:

    
    <?php
    preg_match_all('/\(([H|G]{1}[0-9]+)\)/', $blbdescription, $res);
    
    Code (markup):
    Also take a min to check this out: https://regex101.com/r/xmrbJN/1 will explain to you exactly what is going on with the regular expression.
     
    ThePHPMaster, Jul 1, 2018 IP
  9. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #9
    How do I extract the Hebrew and Greek words using UTF-8 encoding?
     
    gilgalbiblewheel, Jul 1, 2018 IP