PHP Reading the URL [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I make the following url to be read:
localhost/index.php?errormsg=wrongpassword
so I want it to set the variable $errormsg to 'wrongpassword' how do I do that? I am pretty sure there is a way using $_GET or $_POST?

You want to use $_GET['errormsg'].
Something like this should do:
if isset($_GET['errormsg'])
{
echo $_GET['errormsg'];
}

$errormsg = $_GET['errormsg']
This should do the trick for you

$_GET['errormsg'] is the answer of your question.

print_r($_GET)
to see all variables in the URL. in this case you want
$_GET['errormsg']

You were as close as ever. A single google would've yielded the answer to you :)
http://php.net/manual/en/reserved.variables.get.php
<?php
// use htmlspecialchars() to clean up url-encoded characters
$error_message = htmlspecialchars($_GET["errormsg"]);
echo 'Error: ' . $error_message;
?>
prints: "Error: error_here", if url = ...?errormsg=error_here

Related

PHP Code Session Not Working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
My PHP code dosnt seem to be working and I dont Know Why when Ever I Use this code it will Make The whole webpage appear white.I think the problem is Here Somewhereecho Hello, (.$_SESSION['username'], ENT_QUOTES, 'UTF-8');Thanks In Advance
session_start();
if(!isset($_SESSION['user']) && empty($_SESSION['user'])) {
echo '<b>Log In</b>';
}
else {
echo Hello, (.$_SESSION['username'], ENT_QUOTES, 'UTF-8');
echo '</br></b>';
echo '<b>Log Out</b>';
}
When your page goes white, it usually means you have a fatal error in your code and need to check your logs, or turn on error_reporting.
In this case you're missing quotes, have the concatenation a bit messed up, and appear to be missing a function call (probably htmlspecialchars).
Also, you're checking $_SESSION['user'] a few lines before in your code, are you sure you don't mean to echo that here instead of $_SESSION['username']?
I think you want to change that line to:
echo "Hello, " . htmlspecialchars($_SESSION['user'], ENT_QUOTES, 'UTF-8');

How to display HTML code as HTML code using PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the PHP code as below:
<?php
echo "<tr></tr>";
//ouput I want : <tr></tr>
?>
When Output I want to display <tr></tr>.But I don know whitch function that I should use for this,anyone know help me please,thanks
Try with htmlentities like
<?php
echo htmlentities("<tr></tr>");
?>
Follow this LINK
You can also make use of htmlentities()
<?php
echo htmlentities("<tr></tr>");
?>
Try this
$output = htmlspecialchars("<tr></tr>", ENT_QUOTES);
Use htmlentities
<?php
echo htmlspecialchars('<tr></tr>');
?>

Remove specific match from a string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to remove a particular match of characters from a string.
For example i have strings;
topics-p10-new-model-cars
topics-p20-new-model-cars
topics-p30-new-model-cars
topics-p40-new-model-cars
Then i need the results as,
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
That means i want to remove p10-,p20-,etc..
.Those are the page numbers. It may be any number..
How can i do this..? Thanks in advance
Try this:
$result = preg_replace('/\-p\d+/', '', $string);
Note: I'm assuming that the string format does not change (I mean this [topics-p10-new-model-cars]). If my assumption is right.
Then you can do this
if (textBox1.Text.Contains("-p10-"))
{
//topics-p10-new-model-cars
String[] splited = textBox1.Text.Split(new char[] {'-'});
String rString = String.Format("{0}-{1}-{2}-{3}",
splited[0],splited[2],splited[3],splited[4]);
MessageBox.Show(rString);
}
//OR This method
if (textBox1.Text.Contains("-p10-"))
{
String result = textBox1.Text.Replace("p10-", "");
MessageBox.Show(result);
}
With 'preg-replace'::
For, example:
<?
echo preg_replace('/p[0-9]+\-/', '', 'topics-p10-new-model-cars');
?>
Follow this link:
http://www.php.net/manual/en/function.preg-replace.php

PHP variable and array combinations [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
How can i do so this code will output a yes if the $weapon is equal to $nopa, else it would output a no. Any ideas?
you can use in_array from PHP documentation stated here: http://php.net/manual/en/function.in-array.php
Check the PHP function "in_array"
http://php.net/manual/en/function.in-array.php
if ( in_array($stringVar, $arrayVar) ) {
//do something
}
Careful about case, however.
If needle is a string, the comparison is done in a case-sensitive
manner.
check out the built-in in_array function:
http://php.net/manual/en/function.in-array.php
this is what You want:
<?
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
if (in_array($nopa,$weapon1)){
echo 'YES';
} else {
echo 'NO';
}
?>
WORKING CODE

Php:Return a String from a function [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The simple program is not returning the string,Please help.
<?php
function returnStr() {
return "fooBar";
}
$str=returnStr();
echo $str;
}
?>
It's a parse error:
$str=returnStr();
echo $str;
} // WHAT IS THIS BRACKET DOING HERE?
There's a fatal error tokenizing the code due the trailing/unmatched '}' remove that and the code will work. Then spend some time thinking about why you didn't know this already
There's an error in your code. The last } is useless.

Categories