Encoding equals symbol to html equivalent 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 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

Related

I want to replace two separate words with only one word in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
I want to replace two words in a sentence with one word, like in the following example:
Kippa's luck was very bad yesterday.
I want to change it to:
Kippa's was very misfortune yesterday.
In this example, I know it has no sense, but it's just an example,
I want to replace (luck & bad) with the word (misfortune) in php.
Thank you
You can pass arrays as parameters to str_replace
<?php
$youText = "Kippa's luck was very bad yesterday.";
$replace_1 = ["bad", "luck"];
$replace_2 = ["misfortune", ""];
$result = str_replace($replace_1, $replace_2, $youText);
echo $result;
?>
Thank you. but actually there are alot of different words to be changed with, not only one word. I need something like this: **
$URLContent = "he has a bad luck. but he is ok, a good man";
$remove_multi = array(['bad', 'luck'],
['good', 'man']);
$replace_multi = array(['misfortune', ''],
['nice', '']);
$URLContent = str_replace($remove_multi, $replace_multi, $URLContent);

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

Stop PHP from adding backslashes to 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 6 years ago.
Improve this question
I have a function that builds a regex based on an array. The problem is that PHP keeps adding backslashes to some of the characters, and it keeps messing up the regex.
Here is my function:
private static $allowedPermissions = [
/*SV*/
'user_add',
'user_edit',
'user_delete',
'user_view'];
$regexrule = '/';
foreach (self::$allowedPermissions as $allowedPermission) {
$regexrule .= '\b'.$allowedPermission.'\b';
if(end(self::$allowedPermissions) !== $allowedPermission) $regexrule .='|';
}
$regexrule .= "/";
return 'regex:'.$regexrule;
It is adding backslashes where I don't expect them:
regex:\/\\buser_add\\b|\\buser_edit\\b|\\buser_delete\\b|\\buser_view\\b|\\bpatient_add\\b|\\bpatient_edit\\b|\\bpatient_delete\\b|\\bpatient_view\\b|\\bmake_per\\b|\\bmake_per_withconfirmation\\b|\\bconfirm_per\\b|\\beval_per\\b|\\beval_per_withconfirmation\\b|\\bconfirm_per_report\\b\/
Backup screenshot of regex
Is there a workaround?
I found out that returning it in json format was adding the backslashes.

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);

url encoding issue. instead %50 its passing space..how to pass %50 through urlencoded url [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 have tried to pass a variable trough url... its %50.
I am doing urlencoding to pass other languages through the url.
At that time %50 also been converted to a space or something else.
Can anyone help me to find out a way to send %50 as a variable through urlencoded link(url).
<?php
$string = '%50';
echo $encoded = urlencode($string);
// returns %2550
echo urldecode($encoded);
// returns %50
?>
So if you want to pass $string to a url you write something like:
http://yoursite.com/script.php?string=$encoded
To get your original string value you can just use $_GET in your script.php:
echo $_GET["string"];
// returns %50

Categories