I am trying to use url rewriting on my website and I want to use the list()
and explode()
functions to get the right content.
Currently my code looks like this:
list($dir, $act) = explode('/',$url);
In this case $url
is equal to everything after the first slash in the absolute url i.e. http://example.com/random/stuff => $url = random/stuff/
this would work fine, but if I want to go to http://example.com/random/
then it will print a notice on the page. How do I stop the notice from showing up do I need to use something other than the list()
function?
Right now the notice is "Notice: Undefined offset: 1..."
Thanks for the help!
The explode() method converts each element of the specified column(s) into a row.
The explode() is a Python function used to transform or modify each member of an array or list into a row. The explode() function converts the list elements to a row while replacing the index values and returning the DataFrame exploded lists.
The explode function is utilized to "Split a string into pieces of elements to form an array". The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.
The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.
Try this :
list($dir, $act) = array_pad(explode('/',$url), 2, '');
array_pad
complete the array with your values, here is : ''
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With