PHP: str_split() function
The str_split() function is used to convert a string to an array.
(PHP 5 )
|string_name||The string to be split.||Required||String|
|split_length||The length of the chunk.||Optional||Integer|
If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise, each chunk will be one character in length.
FALSE is returned if split_length is less than 1.
If the split_length length exceeds the length of the string, the entire string is returned as the first (and only) array element.
Value Type: Array.
<?php $string_name='Welcome to w3resource.com'; print_r(str_split($string_name)); echo '<br>'; print_r(str_split($string_name,4)); echo '<br>'; ?>
Array (  => W  => e  => l  => c  => o  => m  => e  =>  => t  => o  =>  => w  => 3  => r  => e  => s  => o  => u  => r  => c  => e  => .  => c  => o  => m ) Array (  => Welc  => ome  => to w  => 3res  => ourc  => e.co  => m )
PHP: Tips of the Day
<script> var myvar = <?php echo json_encode($myVarValue); ?>; </script>
Using json_encode() requires:
- PHP 5.2.0 or greater
- $myVarValue encoded as UTF-8 (or US-ASCII, of course)
Since UTF-8 supports full Unicode, it should be safe to convert on the fly.
Note that because json_encode escapes forward slashes, even a string that contains </script> will be escaped safely for printing with a script block.
Ref : https://bit.ly/34f0Dym
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework