So I have this code (which is irrelevant I guess):
<!-- Ad Code - DO NOT MODIFY -->
<?php
function isUsignMobileDeviceTrue() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
// If the user is on a mobile device, show ads
if(isUsignMobileDeviceTrue()): ?>
<?php echo file_get_contents("https://www.example.com/ad1.php");
echo 'https://www.example.com';
?>
<?php endif;?>
<!-- //Ad Code End-->
Basically I want the above code to be shown as text. Same as the above... So that a user could copy and paste.
I'm using this inside the .php file.
I have tried <code> my above code </code>
in Wordpress, but it still tries to execute the code. I guess this works in Post only.
Is there any simple code line to wrap around so that php/html/javascript code would show as plain text, instead of trying to execute it?
My Answer:
You can use the
tag in HTML to display code as plain text. Here is an example of how you can wrap your PHP code in thetag:
<!-- Ad Code - DO NOT MODIFY -->
<?php
function isUsignMobileDeviceTrue() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
// If the user is on a mobile device, show ads
if(isUsignMobileDeviceTrue()): ?>
<?php echo file_get_contents("https://www.example.com/ad1.php");
echo 'https://www.example.com';
?>
<?php endif;?>
<!-- //Ad Code End-->
This will display your PHP code as plain text on the webpage, allowing users to copy and paste it without it being executed.
Rate this post
4 of 5 based on 9068 votesComments