PHP rawurldecode() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
URL

Definition

In PHP, rawurldecode() turns every %XX sequence in a string back into its character.

Unlike urldecode(), it keeps a plus sign as a plus sign. It matches the output of rawurlencode().

Syntax

Call rawurldecode() with the values you need. Start with this line.

PHP
$text = rawurldecode($encoded);
CallWhat it does
rawurldecode("Hello%20World")Returns "Hello World".
rawurldecode("a+b")Returns "a+b" (plus is kept).

Use it for URL paths. Use urldecode() for form and query data where + means a space.

Library declarations
PHP
rawurldecode(string $string): string

Parameters

ParameterDescription
stringRequired. The URL-encoded string to decode.

Return Value

Return ValueDescription
stringThe decoded string.

PHP Examples

Example 1 — Decode a URL Path Text

Turn %20 and %21 back into a space and an exclamation mark.

PHP
<?php
$encoded = "Hello%20World%21";

echo rawurldecode($encoded), PHP_EOL;

How It Works

  1. Start with encoded text. %20 is a space and %21 is !.
  2. Call rawurldecode(). Each %XX becomes one byte.
  3. Get the readable text. Here you see Hello World!.
  4. Print it. echo shows the result.

Example 2 — Compare with urldecode()

A plus sign stays a plus with rawurldecode(), but becomes a space with urldecode().

PHP
<?php
$text = "a+b%2Bc";

echo rawurldecode($text), PHP_EOL;
echo urldecode($text), PHP_EOL;

How It Works

  1. Use a string with + and %2B. %2B is an encoded plus sign.
  2. rawurldecode() keeps the first +. Only %2B changes to +.
  3. urldecode() changes the first + to a space.
  4. Pick the right function. Use raw for paths and the other for forms.

Example 3 — Decode a File Name from a URL

Take the last part of a URL path and decode it.

PHP
<?php
$path = "/files/My%20Report.pdf";

$name = basename($path);

echo rawurldecode($name), PHP_EOL;

How It Works

  1. Start with a URL path. It has an encoded space.
  2. Take the last part. basename() returns My%20Report.pdf.
  3. Decode it. %20 becomes a space.
  4. Use the file name. It is now ready to show to a user.

Frequently Asked Questions

rawurldecode() decodes %XX sequences in a string and returns the plain text. It follows RFC 3986.
rawurldecode(string $string): string. Pass the encoded string.
urldecode() also turns + into a space. rawurldecode() leaves + as it is.
No. PHP already decodes $_GET and $_POST values for you. Decoding again can break values that contain a % sign.
Use rawurlencode() to create text that rawurldecode() can decode.

Next: rawurlencode()

rawurlencode() encodes a string for use in a URL path using RFC 3986.

rawurlencode() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful