Jump to content
php.lv forumi
  • 0

atgriezt atlikumu no split


Wuu

Question

Pēc pieprasījuma no php atnāk šādas struktūras strings "recive"

9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas

9 - ID

http - adrese

un beigas - nosaukums

 

var id = recive.split(" ",3);

Sākuma domāju ka tikšu galā ar parastu split ,bet nesanāk un tas arī ir loģiski.

Kā man atdalīt "Kaut kas" ?

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Ka ta

$string = '9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas';
list($id,$url,$com) = explode(' ', $string, 3);

 

Citāts nebija vajadzīgs

Link to comment
Share on other sites

  • 0

Sorry, my false. Sadalu nosaukumi baigi nepamanami.

 

Ideja tak nemainas.

 

var longstring = "Most of the time Amrit is confused — OK, not most of the time";
var brokenstring = longstring.split(" ",3); 

 

brokenstings, dalisies aiz komatiem

Edited by cucumber
Link to comment
Share on other sites

  • 0

var longstring = "Most of the time Amrit is confused — OK, not most of the time";
var brokenstring = longstring.split(" ",3);
alert(brokenstring[2]);

Tu manu postu neizlasīji :(

Tur tak tāds pats variants atgriež tik "the"

Edited by Wuu
Link to comment
Share on other sites

  • 0

Kaut kas dabut shita, ja atstarpju vairak par 3 nebus.

var longstring = "9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas";
var brokenstring = longstring.split(" "); 

var totChars = 0;
for ( i = 0; i < 3; i++) {
totChars += brokenstring[i].length;
}


alert(longstring.substring(totChars-2));

Link to comment
Share on other sites

  • 0

Varbūt šādi:

var longstring = "Most of the time Amrit is confused — OK, not most of the time";
var brokenstring = longstring.split(" ");
for(x=3;x<brokenstring.length;x++){
brokenstring[2] = brokenstring[2] + " " + brokenstring[x];
}

Vai arī šādi:

var longstring = "Most of the time Amrit is confused — OK, not most of the time";
brokenstring = longstring.slice(0,longstring.indexOf(" ",1)).split(" ");//Neesmu pārliecināts, vai iekš indexOf vajag 1 vai 2
brokenstring[] = longstring.slice(longstring.indexOf(" ",1)+1);

Link to comment
Share on other sites

  • 0
var 
 s="9 http://supermens.lv/upload/thumbs/e85016e22b68b05155e601ae80cc02bd.png Kaut kas",
 id=false,
 url=false,
 name=false;
if(m = s.match(/(\d+)\s+(.*?)\s+(.*)/)) {
 name = m.pop(); url = m.pop(); id=m.pop();
}

alert(id + "\n" + url + "\n" + name);

?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...