fork download
  1. <?php
  2. function path($page, $id, $raw = false){
  3.  
  4. if(!$raw){
  5. $id = urlencode($id); // I do need to get rid of that, that is why I wanted to use the raw-filter, simulated by the third argument.
  6. }
  7.  
  8. switch($page){
  9. case 'article_edit':
  10. return "'article/" . $id . "/edit'";
  11. break;
  12. case 'comment_add':
  13. return "'comment/" . $id . "/add'";
  14. break;
  15. }
  16.  
  17. }
  18. ?>
  19. <script>
  20. // this is not working, as $id gets encoded.
  21. for(var i=1; i<=3; i++){
  22.  
  23. document.write(<?= path('article_edit', "' + i + '") ?> + '<br>\n');
  24.  
  25. }
  26.  
  27. // this is working, due to the use of the raw-filter simulation
  28. for(var i=1; i<=3; i++){
  29.  
  30. document.write(<?= path('article_edit', "' + i + '", true) ?> + '<br>\n');
  31.  
  32. }
  33. </script>
Success #stdin #stdout 0.03s 25888KB
stdin
Standard input is empty
stdout
<script>
	// this is not working, as $id gets encoded.
	for(var i=1; i<=3; i++){

		document.write('article/%27+%2B+i+%2B+%27/edit' + '<br>\n');

	}
	
	// this is working, due to the use of the raw-filter simulation
	for(var i=1; i<=3; i++){

		document.write('article/' + i + '/edit' + '<br>\n');

	}
</script>