How to encode base_64 without slash in PHP?

Stack Overflow Asked by Burhan on January 1, 2022

Orignal String:

$string = "Home/Gallery/Images/Mountains";

Then I encode this string into base64_encode():

echo base64_encode($string);



But I want to show this output:


Look at the Slashes

means I don’t want to that base64_encode() never encode a slash "/" and show slash in orignal form but other string always convert into base64_encode()

There is someone here who can answer me and please also tell how to decode?

(Sorry for bad english)

One Answer

You can split it and use the single parts to encode. You can not exclude any chars.

Note, you will gain some extra padding bytes!

$string = "Home/Gallery/Images/Mountains";

echo join('/', array_map(fn($v) => base64_encode($v), explode('/', $string)));


Answered by Markus Zeller on January 1, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP