CAML Encode and Decode

url encode
Use the CAML encoder and decoder to encode or decode CAML while working with SharePoint Data Source Control queries. This script utilizes both HTML rendering to decode and a PHP function to encode. And, of course, I have included the simple script below for those that are curious.

show me!
 <title> CAML Encode and Decode</title>

 .outbox {
 border:1px dashed #9E7760;


<body style="background-color:#FFFFFF;">

<p style="text-align:center;font-family:verdana;font-size:20px;">sharepoint caml encode and decode</p>


 if ($_POST['dir'] == "e") {
 echo camlencode($_POST['caml']);
 } elseif ($_POST['dir'] == "d") {
 echo $_POST['caml'];


 <form method="post" action="index.php">
 <input type="text" name="caml" size="50" />

 <select name="dir">
 <option value="e"<?php if($_POST['dir'] == "e"){echo "selected";} ?>>Encode</option>
 <option value="d"<?php if($_POST['dir'] == "d"){echo "selected";} ?>>Decode</option>

 <input type="submit" value="process" />

<p style="text-align:center;font-family:verdana;font-size:12px;">note: the decode utilizes standard HTML rendering and the encode will only change the following characters (", <, >).</p>

<p style="text-align:center;font-family:verdana;font-size:10px;"><a href="">a simple service of</a></p>



function camlencode($mycamlstr) {

 $mycamlstr = str_replace("<", "&amp;lt;", $mycamlstr);
 $mycamlstr = str_replace(">", "&amp;gt;", $mycamlstr);
 $mycamlstr = str_replace("\"", "&amp;quot;", $mycamlstr);

 return $mycamlstr;

function camldecode($mycamlstr) {

 $mycamlstr = str_replace("&lt;", chr(60), $mycamlstr);
 $mycamlstr = str_replace("&gt;", chr(62), $mycamlstr);
 $mycamlstr = str_replace("&quot;", chr(34), $mycamlstr);

 return $mycamlstr;



  1. Front End Dev in SharePoint Is...Draining said:

    Thank you, thank you! Not sure if I just wasn’t Googling for the right term or what, but I expected to find more of these quick CAML encode/decode tools online. Glad I finally found yours. This is much faster than the alternative ways that involve putzing around with SPD, etc.Thanks!

    August 25, 2012

Leave a Reply

Your email address will not be published. Required fields are marked *