Jump to content
php.lv forumi
  • 0

atgriezt atlikumu no split


Question

Posted

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" ?

10 answers to this question

Recommended Posts

  • 0
Posted

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

  • 0
Posted (edited)

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
  • 0
Posted (edited)

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
  • 0
Posted

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));

  • 0
Posted

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);

  • 0
Posted

Tas īsti neder ,es domāju varbūt to "space" aizstāt ar kādu specifisku simbolu ,un visas problēmas būtu atrisinātas. Tik kādu lai izvēlas?

  • 0
Posted
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);

?

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...