This question already has answers here:
How to show <div> tag literally in <code>/<pre> tag?
(11 answers)
Closed 2 years ago.
Im actively practicing with php regex and got stuck with a replace function as it shows absolutely different results from tutorial I copied it from.
So the function preg_replace('/\{([a-z]+)\}/', '(?P<\1>[a-z-]+)', '{controller}\/{action}') should give me this result in the output: (?P<controller>[a-z-]+)\/(?P<action>[a-z-]+). phpliveregex.com confirms that https://www.phpliveregex.com/p/wIF
However, this is what my browser on my localhost is outputing me in fact: (?P[a-z-]+)\/(?P[a-z-]+).
How is that possible? Is my php broken or the preg_replace function is working differentely now? My php version is 7.4.4
Your browser interprets the <controller> and <action> as html tags and tries to parse them that leads to deleting them. see this to see how can you show tags literally using html encoding.
(?P<controller>[a-z-]+)\/(?P<action>[a-z-]+)
<br/>
(?P<controller>[a-z-]+)\/(?P<action>[a-z-]+)
You can maybe replace it with (?P<\1>[a-z-]+)
Related
This question already has answers here:
PHP: Variables in a Postgresql Query
(2 answers)
Closed 3 years ago.
I’m working on a project where I need to use postgresql to update info. I need to take
Martin’s chik ‘n’ chips
And make change it to
Martin\’s chik \’n\’ chips
How would I do this? I’ve looked at other posts, and found out to use substr() to create the new string and strpos() to find the ‘s, and even setting a new variable to keep the position of the previous ‘
Edit: thanks everyone, clearly didn’t do enough research!
If in PHP:
Check out str_replace(). e.g.
$text = "Martin’s chik ‘n’ chips";
$apostrophe = array("'","`","‘","’");
$newtext = str_replace($apostrophe,"\'",$text);
In this specific example, if you don't have any of the 'fancy' apostrophes, check out addslashes() as this will solve everything for you
This question already has answers here:
Is there anyway to have Notepad++ highlight both PHP and HTML at the same time?
(2 answers)
Closed 7 years ago.
<html>
This is file is called "example.php".<br>
<?php print "=== This is printed by a php 'print' statement<br>"; ?>
This text is after the embedded php.
</html>
When either of the html tags, its mate is found, and both are given a distinctive color.
But the php tags don't find their mates, and don't get highlighted. How can I get that behavior?
Save your file in .php extention in notepad ++.
If that does not sort the problem download the latest version of notepad++ from here.
Here : it works see :) -
Let me know if anyother issues :)
This question already has answers here:
How do I ignore a moved-header with file_get_contents in PHP?
(3 answers)
Closed 8 years ago.
I am trying to get contents of a Website with simple html DOM as follows:
<?php
include_once('../simple_html_dom.php');
$html = file_get_html('http://www.opaltransfer.com/en');
echo($html);
?>
When i run this on my localhost everything works fine, However when i try to run it on a remote server i am getting
Found
The document has moved here.
Why? and what can i do to get it to work? Thanks in advance
You're missing a / at the end of the URL.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to properly escape html form input default values in php?
I am facing problem on facing </textarea> element.
I am working on whole php file edit. If the php file has </textarea> tag it closes the files codes.
E.g.
$data=file_get_contents($file);
..
'<textarea>'
'.$data.'
'</textarea>'
..
The problem is:
if contain the </textarea> tag in data, my codes truncted by the tag. Because </textarea> is end tag of textarea values. Any solve there to not execute </textarea> tag(which contained $data)?
Try cleaning up $data before outputting it, such as:
'.htmlentities($data).'
Also, take a look at the available flags for the function in the PHP documentation.
This question already has answers here:
Getting actual value from PHP SimpleXML node [duplicate]
(4 answers)
Closed 8 years ago.
I am using simplexml_load_string for XML packets. In my scenario, the XML string I want to convert is known as k.
My problem, however, is that when I use k, tags still remain that weren't parsed (<k>, <\k>).
For example, I use
$x->k, and I get back <k>DATA I WANT HERE<\EK>.
How do I get rid of these?
What the code does: It connects to a game and logs in.
Use InnerNode to get the value without the tags:
$x->k->InnerNode
You can also do a typecast:
(string)$x->k
I tried this and seem to be getting the string.
<?php
$str = "<msg t='sys'><body action='rndK' r='-1'><k>qH~e9Gmt</k></body></msg>";
$xml = simplexml_load_string( $str );
echo $xml->body->k; // gives 'qH~e9Gmt'
?>