PHP: Splitting a string? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: Other (
https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (
https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: PHP: Splitting a string? (
/showthread.php?tid=476314)
PHP: Splitting a string? -
Jantjuh - 17.11.2013
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?
Re: PHP: Splitting a string? -
Camacorn - 17.11.2013
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
Re: PHP: Splitting a string? -
Djole1337 - 17.11.2013
Quote:
Originally Posted by Camacorn
|
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.
Re: PHP: Splitting a string? -
Jantjuh - 17.11.2013
Quote:
Originally Posted by Djole1337
No.
str_split() is made for that.
You can use it like:
Good luck.
|
Got it, thanks ~ !