Php 你能给我一些关于我工作的建议吗
这是我的第一个PHP问题: 有两个输入字符串Php 你能给我一些关于我工作的建议吗,php,Php,这是我的第一个PHP问题: 有两个输入字符串$n1和$n2。第一个单词必须是一个长单词,例如“queryselector”。然后,第二个输入是第一个输入字符串(查询、tor…)的子字符串。我必须在第一个输入中找到第二个输入的字符串位置,即它在哪里,在开头或结尾 <!DOCTYPE html> <html> <head></head> <body> <form method='get'> <inp
$n1
和$n2
。第一个单词必须是一个长单词,例如“queryselector”。然后,第二个输入是第一个输入字符串(查询、tor…)的子字符串。我必须在第一个输入中找到第二个输入的字符串位置,即它在哪里,在开头或结尾
<!DOCTYPE html>
<html>
<head></head>
<body>
<form method='get'>
<input type="text" name="n">
<input type="text" name="a">
<button>push</button>
</form>
<?php
$n1 = $_GET['n'];
$n2 = $_GET['a'];
echo $n1, $n2;
if (strpos($n1,$n2) !== ''){
if (strlen($n2) !== '') {
strpos($n1);
}
}
?>
</body>
</html>
推
我想这就是你需要的
<?php
$n1 = $_GET['n'];
$n2 = $_GET['a'];
echo $n1, $n2;
if(strpos($n1, $n2) !== ''){
if(strlen($n2) !== ''){
if(strpos($n1, $n2) + strlen($n2) == strlen($n1)) //eg., tor
echo 'At the end';
else if(strpos($n1, $n2) == 0) //eg., query
echo 'In the beginning';
else //eg., sel
echo 'Somewhere in between';
}
}
?>
推
请使用下面的PHP
代码进行检查:
<?php
$n1 = 'queryselector';
$n2 = 'tor';
// echo $n1, $n2;
if (strpos($n1,$n2) !== '') {
if (strlen($n2) > 0) {
echo 'Find substring at position: ' . strpos($n1, $n2);
if (substr($n1, 0, strlen($n2)) == $n2) {
echo ' & is at Starting.';
} else if (substr($n1, '-'.strlen($n2)) == $n2) {
echo ' & is at Ending.';
} else {
echo ' & is in Between.';
}
}
}
?>
我已经直接放置了字符串,您可以像以前一样将其动态化(比如$\u GET
)
这是一本书。你也可以在这里查一下
输出类似于:Find substring at position:0&处于开始位置。
您的要求并不明确。您可以使用isset()
检查$\u GET[x]
是否已定义。首先,单击按钮,添加type=“submit”,您没有提交表单单击按钮以提交表单。您的意思是要在长字符串中找到小字符串吗?@Martin,按钮的默认类型为提交(除非浏览器为IE7或更旧版本)。
<?php
$n1 = 'queryselector';
$n2 = 'tor';
// echo $n1, $n2;
if (strpos($n1,$n2) !== '') {
if (strlen($n2) > 0) {
echo 'Find substring at position: ' . strpos($n1, $n2);
if (substr($n1, 0, strlen($n2)) == $n2) {
echo ' & is at Starting.';
} else if (substr($n1, '-'.strlen($n2)) == $n2) {
echo ' & is at Ending.';
} else {
echo ' & is in Between.';
}
}
}
?>