PHP Unable to do complete regex [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to run
$var = "Guru & Hari - Priya";
if(preg_match('/^[A-Za-z0-9& -]+$/', $var)){
echo "Hi";
}else{
echo "bye";
}
Somehow code is unable to understand "&".
Per regex101.com above code is fine.
Please share why PHP is unable to recogonise &

not-an-answer
You should mention/consider your string source.
What you see as & is probably & in your text value.
The browser rendition is not always an exact representation of your data.
See also: PHP Regex: Matching Ands - & and &

Related

Why PHP cannot execute the echo "<?"? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Can some of you tell me please why when I echo "<?", the <? is not displayed?
I'm sorry, maybe it's very stupid question, but I need to dig this language more deeper.
If you view the source it will be there. Its because the browser thinks its a tag.
Fix it by using htmlentities().
echo htmlentities("<?");

php remove empty single comment [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have code like this
function get_id(){
return 1;
//
}
I want to remove all // inside the source code, but only those stand by it own, on a newline just like the example here. Nothing much nothing more. How can I do it?
Search using this regex:
^\s*\/\/\s*$
and replace by empty string.
If using PHP you can use \h (horizontal space) instead of \s:
$code = preg_replace('~^\h*//\h*$~m', '', $code);

PHP does not copy the file properly [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
im copying a file from another domain. It does not give me any errors but the files does not get recognized and its different size from the original file. Its the same extension i checked. so im kinda clueless.
if (!copy('http://maholi.com/image/data/Products/Linen - Juvenile and Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/resources/categories/tttt6.jpg')) {
echo "failed";
}
any ideas?
This works fine for me:
if (!copy('http://maholi.com/image/data/Products/Linen%20-%20Juvenile%20and%20Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/tttt6.jpg')) {
echo "failed";
}
Edit: URL's are not allowed to contain spaces. See "Is a URL allowed to contain a space?". Your web browser will automatically encode illegal characters, making you believe they are allowed.

how to $_GET when it has a ' in the text [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I pass a variable called txt from one query on a web page to another web page using
<?php echo $_GET['txt'];?>
the problem some time the text will have a word like don't in it. the (') causes things to just stop. I need to output the variable as read from the database which would include any text that was in the field
When using $_GET you should use urlencode() and urldecode().

PHP code does not execute [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I started learning PHP today and I've been trying to make a "Hello World" program, but when I type the code into the editor it does not appear in the browser, it's commented. What might be the issue ? I have XAMPP installed, and enabled Apache.
Code: http://i.imgur.com/khOPvSD.png
Browser: http://i.imgur.com/uQd25Qb.png
You are having
<?echo
Change to <?php
Every code that is PHP must be within the <?php ?> tags.

Categories