0
<span id="description">
 <?php echo $itemdesc ?>
</span>

The above PHP outputs part of the URL that displays something like this:

 This%2520is%2520the%2520 %2520thing%2520 %2520purchased%2520

And what I want is this:

 This is the thing purchased

Here's my code. My problem is the /g tag (global) doesn't seem to be working.

<script>
  oldhtml = $('#description').html();
  var newhtml = oldhtml.replace("%2520"/g, " ");
  $('#description').html(newhtml);
</script>

1 Answer 1

1

Instead of ", add / to cover regex.
That is /%2520/g.
When you use "%2520'/g, there is no regex to associateg` with.

var newhtml = oldhtml.replace(/%2520/g, " ");
$('#description').html(newhtml);

Alternatively, you can use

.replaceAll("%2520"," ");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.