What is wrong with strpos()? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
Have code:
$url = 'http://www.domain.com/dir1/dir2/dir3/page-2.html';
if ($strpos = strpos('/page', $url)) echo '1';
else echo '2';
It shows only '2'.
How can I fix it?

Change arguments places
strpos($url, '/page')
strpos

Actually the syntax for function was mismatched I think.
use this
$stropos = stripos($url,"/page");
echo $strpos;

Please add === identical compare in if condition and correct the position of strpos parameters
$url = 'http://www.domain.com/dir1/dir2/dir3/page-2.html';
if ($strpos == strpos($url, '/page')) echo '1';
else echo '2';

Related

how to add string to variable in php? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
i just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>

Dynamic Matrices in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
I have written the PHP code below in order to create a dynamic matrix with different count of columns per row but PHPStorm says the row variable is not defined. please help.
class reply
{
public $text;
private $row = array(array());
private $rowIndex = 0;
private $colIndex = 0;
public function Add($menu)
{
$this->$row[$this->rowIndex][$this->colIndex] = $menu;
$this->colIndex++;
}
public function NextRow()
{
$this->rowIndex++;
$this->colIndex = 0;
}
}
$this->$row is incorrect, it should be $this->row.

Shorten String function not working properly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have this little function to stop a string being too long but it dosen't seem to work. I'm assuming i've done something wrong?
function trimString($string, $maxChar) {
$string = (strlen($string) > $maxChar) ? substr($string,0,$maxChar).'...' : $string;
}
I was using it like this:
echo trimString($row['mainTitle'], 30);
Thanks
You forgot to return value from function. Try
function trimString($string, $maxChar) {
return (strlen($string) > $maxChar) ? substr($string,0,$maxChar).'...' : $string;
}

PHP console does not echo [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement

$variable = $url + static_page.php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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
Improve this question
I would like to uplaod files using cURL but can't figure out how I can use $url array.
For example:
$urls = array("http://images.domain.com/",
"http://flash.domain.com/",
"http://other.domain.com/"
);
foreach ($urls as $url) {
I'm trying this but without success:
$upload = "$url ."upload/upload.php";
Any advice? :)
Thanks
You need to take out the first quote for it to work
$urls = array("http://images.domain.com/",
"http://flash.domain.com/",
"http://other.domain.com/"
);
foreach ($urls as $url) {
$upload = $url ."upload/upload.php";
}

Categories