(PHP Extension) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
// To URL encoding a string:
$s = 'Why a > b?';
$sb = new CkStringBuilder();
$success = $sb->Append($s);
// URL encode the string.
$sb->Encode('url','utf-8');
// Show the URL encoded string:
$sEncoded = $sb->getAsString();
print $sEncoded . "\n";
// The result is: Why%20a%20%3E%20b%3F
// If you prefer "+" instead of "%20" for SPACE chars:
$numReplaced = $sb->Replace('%20','+');
print $sb->getAsString() . "\n";
// Output is: Why+a+%3E+b%3F
// To decode:
$sb->Decode('url','utf-8');
print $sb->getAsString() . "\n";
// Result is: Why a > b?
?>
|