PHP: Splitting a string?
#1

Edit: Got it, thanks guys!

---

Hey guys, just a quick question about PHP. What I'd like to do is split a string like this..

Код:
$var = "11711201317192171120131719317112013171941711201317195171120131719";
..into multiple strings, like these: (Inside an array, maybe?)

Код:
1171120131719
2171120131719
3171120131719
4171120131719
5171120131719
The amount of characters between each 'split' is always the same: 13.

How could I accomplish this?
Reply
#2

Try using the explode function in PHP.

Small tutorial:
http://php.net/manual/en/function.explode.php

EDIT, found a better explanation:
http://www.homeandlearn.co.uk/php/php7p5.html
Reply
#3

Quote:
Originally Posted by Camacorn
Посмотреть сообщение
Try using the explode function in PHP.

Small tutorial:
http://php.net/manual/en/function.explode.php

EDIT, found a better explanation:
http://www.homeandlearn.co.uk/php/php7p5.html
No.

str_split() is made for that.


Код:
$var = "11711201317192171120131719317112013171941711201317195171120131719";

$var = str_split($var, 13);

var_dump($var);

Output:
array(5) {
  [0]=>
  string(13) "1171120131719"
  [1]=>
  string(13) "2171120131719"
  [2]=>
  string(13) "3171120131719"
  [3]=>
  string(13) "4171120131719"
  [4]=>
  string(13) "5171120131719"
}
You can use it like:
Код:
echo $var[0]; // 1171120131719
Good luck.
Reply
#4

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
No.

str_split() is made for that.

You can use it like:

Good luck.
Got it, thanks ~ !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)