AaronJ
AaronJ

Reputation: 1170

How do I split text with strange characters?

I want to split part of this user-entered URL on the slashes (//). Everything I try just returns false or an empty string. How can I do it?

mb_internal_encoding("UTF-8");
$url = urldecode('aaa%BAbbb//ccc%D0ddd');
echo 'url: ' . $url . "\n";
$test = mb_split('//', $url);
$test2 = explode("//", $url);
$test3 = mb_ereg("//", $url);

echo "test: " . json_encode($test) . "\n-----------\n";
echo "test2: " . json_encode($test2) . "\n------------\n";
echo "test3: " . json_encode($test3) . "\n------------\n";

https://3v4l.org/a252W

thanks

Upvotes: 1

Views: 60

Answers (1)

AaronJ
AaronJ

Reputation: 1170

explode() works and json_encode wasn't working to output the results. var_dump and print_r work to output the results.

Upvotes: 1

Related Questions