line break conversion from html to php [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 have html code loaded in array $gh[0] and i am coonverting it to plain text
if i compare with same text loaded into new variable it doesn't works
can someone help with the issue, what should be exact value in $a to match the content in $gh[0]
i want comparsion to be working , what will be output if $gh[0] is converted into plain text especially line break
<?php
$gh[0]="Net inventory (used in)/from<br>Production Activities"
$fg=$gh[0]->plaintext;
$a="Net inventory (used in)/from Production Activities"
if($a == $fg)
{
echo "match";
}
else
{
echo "No match";
}
?>

What about just stripping all elements from the input?
$gh[0]= strip_tags($gh[0]);

If you want to know what the value (of $fg) is, why don't you check it?
There's echo, print_r and var_dump.

Related

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

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

PHP: Replace php code in string [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 want replace php codes in string and running fro server
$x = 1;
$string = "OK:{first}Yes{second}No";
I want replace if($x == 1){ to {first} and } else { to {second}
After run and echo $string , I want result in html :
OK:Yes
How did you come up with this approach? Why not simply:
$string = $x == 1 ? 'OK:Yes' : 'OK:No';
That would get you the string you want based on the value of $x.
Also if you literally mean that you want to do a search-n-replace on the PHP code itself (as #OllyTenerife assumes), then are you going to write it into a file to be executed later, or use eval() or something? Doesn't sound like the right track there... In which case, remodel your code.
$string = str_replace("{first}","if($x == 1)",$string);
$string = str_replace("{second}","} else {",$string);

How to verify that user entered empty string? 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 8 years ago.
Improve this question
I need to know how to verify that the user entered empty string in a sentence if in a string with multiple spaces in blank
Example
" "
if user entered a emṕty string, the program must show an alert as this
echo "The username must not be empty";
Use trim to remove whitespace from a var...
$name = trim($_GET['name']);
if ($name == '') //empty
Try this
if (strlen(trim($yourString)) == 0) {
// Do something
}
If the length of the string is 0 after the spaces are trimmed/removed.

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