javascript - Find Single Quote in Array (JS, jQuery or PHP) -


first, sorry bad english ;)

i have array this:

["47'", "", "messi", "l."] 

(output .split(" "))

sometime its:

["messi", "l.", "", "47'"] 

now need find time (by '), name , lastname have no idea how time (once position of time know position of other). programming skills not best, use code snippets found , try understand , learn them.

for better understanding: loop on this

<tr class="score_row">     <td class="home">47'  <span class="slball"></span>messi l.</td>     <td class="away">ronaldo c.<span="yellowcard"></span> 68'</td> </tr> <tr class="score_row"> ... </tr> 

and want put in json array

{"lastname":"messi","name":"l.","time":"47","type":"slball"} 

this send via ajax php.

i hope understand problem if don't find right words describe problem.

edit: code far

<?php echo "var myvar = setinterval(function(){mytimer()}, ".$config['lotteticker']['time'].");" ?>  function mytimer() {     createjson();         $.ajax({         type: 'post',         url: 'content/liveticker.include.php',         data: {'goals': jsonstring},         success: function(data) {             $("#wrapper").html(data);         }     }); }  mytimer();  function createjson() { jsonobj = [];     $("#live .spiel").each(function() {          var result = $(".score_t", this).text().replace(/\s+/g, '').split(":");          item = {}          item ["home"] = result[0];         item ["away"] = result[1];         item ["homeid"] = $(".heim_hidden", this).text();         item ["awayid"] = $(".gast_hidden", this).text();         item ["gameid"] = $(".id_hidden", this).text();         item ["goalcards"] = [];          $(".score_row:not(.main) .home", this).add($(".score_row:not(.main) .away", this)).each(function() {             goal = {}             if ($(this).text() != "\xa0") {                 goal ["nametime"] = $(this).text().split(" "); //placeholder name, lastname , time                 goal ["typ"] = $("span", this).attr("class");                  item["goalcards"].push(goal);             }          });          jsonobj.push(item);      });      jsonstring = json.stringify(jsonobj);     console.log(jsonstring); } 

output should be:

 [{"home":"1","away":"0","homeid":"18";"awayid":"6","gameid":"34","goalcards":[{"‌​lastname":"messi","name":"l.","time":"47","type":"slball"},{"lastname":"ronaldo",‌​"name":"c.","time":"68","type":"yellowcard"}]}] 

solution (i'm dumb sometimes):

var nametime = $(this).text().split(" "); if ($(this).attr("class") == "home") {     goal ["firstname"] = nametime[2];     goal ["lastname"] = nametime[3];     goal ["time"] = nametime[0].slice(0,-1); } else {     goal ["firstname"] = nametime[0];     goal ["lastname"] = nametime[1];     goal ["time"] = nametime[3].slice(0,-1); } 

when iterate on strings in array, can check if str.indexof("'") > -1 means string contains single quote character.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -