PHP is not closing [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I put in the tag and inside it is this:
$one = "\Images\";
I correctly closed the tag itself, but everything after it is being considered part of the tag.
Full code:
<div id="skyscraper-ad">
<?php
$one = "\Images\";
?>
</div>

In PHP the \ character is used to escape an immediately following character that could be interpreted as 'not part of the string'.
eg. If you were to run this:
echo '\'hello';
it would output: 'hello.
In your code, you're escaping the ending ' which will make PHP throw an error.
echo '\Images\\'; on the other hand will output \Images\

You need to escape the backslashes:
<div id="skyscraper-ad">
<?php
$one = "\\Images\\";
?>
</div>

Related

Escaping regex in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have regexes stored in a txt file. How do I escape them in PHP? preg_quote doesn't help if I use the output in an array, throws fatal error. (The following each are on new lines in the txt file)
/[^a-z\/'"]eval\([^\)]+['"\s\);]+/i
/\$auth_pass\s*=.+;/i
/document\.write\((['"])<iframe .+<\/iframe>\1\);*/i
/preg_replace\s*\(.+[\/\#\|][i]*e[i]*['"].+\)/i
/<\?.+?exec\(.+?system\(.+?passthru\(.+fwrite\(.+/s
/RewriteRule [^ ]+ http\:\/\/(?!127\.).*/i
/<\?[\shp]*\#?error_reporting\(0\);.+?[a-z0-9\/\-\='"\.]{2000}.*?($|\?>)/i
/\<a [^\>]+\>\<span style="color\:\#F1EFE4;"\>(.+?)\<\/span\>\<\/a\>\<span style="color\:\#F1EFE4;"\>(.+?)\<\/span\>/i
/(<!\d)\$[\$\{]*[a-z\-\_0-9]+[\} \t]*(\[[^\]]+\][ \t]*)*\(.*?\)\;/i
/\#(\w+)\#.+?\#\/\1\#/is
/(\$[a-z_0-9]+[=\s\#]+)?create_function\([^,]+,[\s\$\.\[\]a-z_0-9]+[\s\)]+;*/i
/json2\.min\.js/i
/(RewriteCond \%\{HTTP_USER_AGENT\} .+\s+)+RewriteRule \^.*\$ http:\/\/(?!127\.).*/i
/<title>[^<]*hack[3e][rd]/i
I think you need to adjust your call to preg_quote(). Something like this:
Preg_match("|" . preg_quote($str, "|") . "|", $content->content)
See another post with a similar question:
PHP String to Regex

php- Apply formatting on specific HTML tags [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am having an issue that I am rendering a text that was being entered in the DB using text editor.
Now I have some conditions of basis of which I have to apply formatting on some specific tags like if there is a word 'teacher' in a <p> or in <h1> or in <h2> it should be changed to 'student'.
I am not sure how to apply formatting on specific html tags
EDIT
Like I have the following text entered in the DB
<p>teacher</p>
<h1>parent</h1>
<h2>TEACHER</h2>
<h3>PARENT</h3>
<strong>parent</strong>
I want to replace the word teacher with student only if it is in <p> or in <h1> or in <h2>
you can use preg_replace:
$str = '<p>teacher is reading</p>
<h1>parent</h1>
<h2>TEACHER</h2>
<h3>PARENT</h3>
<strong>parent</strong>';
//for word in string too
//i for insensitive
$resp = preg_replace('/<(p|h1|h2)>(.*?)(teacher)(.*?)<\/(p|h1|h2)>/i','<$1>$2student$4<‌​/$5>',$str);
var_dump($resp);
response:
<p>student</p>
<h1>parent</h1>
<h2>student</h2>
<h3>PARENT</h3>
<strong>parent</strong>
I don't know but in the html code is setted this code <‌​/$5> and the result give <??/(tag)>
improved code(cleaned):
from_gist
So here is one way:
str_replace("<p>teacher</p>", "<p>student</p>", $yourText );
http://php.net/manual/en/function.str-replace.php

How to get the source code of current page as a variable in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
for example my page is like below code. I know how to extract "this" from the string by preg_match but how do i get the source code of current page as a variable in php.
<body>
<p>I need to find "this" word from "this" string</p>
</body>
Call ob_start() at the beginning of your script, then ob_get_clean(), at the bottom. It will return the output contents of the script as a String, which can you store in a variable. So, from your example:
<?php ob_start(); ?>
<body>
<p>I need to find "this" word from "this" string</p>
</body>
<?php $foo = ob_get_clean(); ?>

HTML code gets displayed when it should not [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the following PHP code:
<?php
$obrazek = the_post_thumbnail( 'product_page_image' );
list($nic,$nic,$nic,$nic,$nic,$obrazeklink,$nic,$nic,$nic,$nic,$nic) = explode('"', $obrazek);
?>
and $obrazek variable contains
<img width="1560" height="1170" src="http://takopix.com/wp-content/uploads/edd/2015/06/Melbourne-storm-1560x1170.jpg" class="attachment-product_page_image wp-post-image" alt="Melbourne storm">
but the HTML gets recognized even without echo... and explode doesn't work!
The function the_post_thumbnail is used to print the thumbnail markup. It returns nothing. You want get_the_post_thumbnail

Encoding equals symbol to html equivalent php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I attempted encoding a '=' symbol to its html equivalent through the use of:
htmlentities("This is my test and it = this");
The result is:
<p>This is my test and it = this</p>1
Notice how the equals sign is not encoded? I know there is a HTML equivalent.
What is an alternative function I can use to encode this string?
Thanks.
I know there is a HTML equivalent
The equals sign isn't encoded for HTML, there is no reason to do so.
You might be thinking of URL-encoding, which would be %3d:
urlencode("This is my test and it = this");
// => "This+is+my+test+and+it+%3D+this"
There's no need to encode the =; it's HTML-safe. If you really want to, though: =
echo str_replace('=', '=', htmlentities("This is my test and it = this"));
Demo

Categories