Jump to content
php.lv forumi

split


cucumber

Recommended Posts

Uz servera php 4.0

 

php 5 f-ja ?

$arr1 = str_split($str);

$str = "Hello Friend"; kas dot

Array

(

[0] => H

[1] => e

[2] => l

[3] => l

[4] => o

[5] =>

[6] => F

[7] => r

[8] => i

[9] => e

[10] => n

[11] => d

)

 

ka var uzrakstit ar php 4 f-ju split, lai panaktu tadu bashu efektu ?

Link to comment
Share on other sites

tas variants nederas, vajaga tieshi ar regularu izteiksmi //split

Link to comment
Share on other sites

labi savadak jatajumi uzdoshu

 

Vai to var izdarit tikai ar regularu izteiksmi, bez cikliem un pasha veidotam kreisam split f-jam.

Link to comment
Share on other sites

$str = "Hello Friend";
preg_match_all('(.)',$str,$match);
pr($match);

 

bet kam tev ar regex, ja triviālu lietu forumā jāprasa, un dalīt pa burtam ar regex vairāk izskatās pēc zvirbuļu ķeršanas ar ceļa rulli.

Edited by v3rb0
Link to comment
Share on other sites

to -->v3rb0

:D, bet ko darit, ja savadak nevar.

paldies

Link to comment
Share on other sites

Delfina variants atgriež kreisu array'u :>

 

no php manuāļa:

 

<pre>
<?php
$text='Viens tāds un tāda... blablabla!';
$chars = preg_split('//', $text, -1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
?>

Link to comment
Share on other sites

×
×
  • Create New...