Php string If contain echo that string [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 7 years ago.
Improve this question
My Php mysql out put is array i need if string contain particular character i need print that string only
while($row2 = mysqli_fetch_array($result2)) {
echo $row2['link'];
}
Output is:
http://www.videoweed.es/file/b38300afda3e6
http://www.novamov.com/video/303a4428f6c6a
http://www.movshare.net/video/081aaa1356a6b
i need like this
if (strpos($a,'videoweed') !== false) {
echo $row2['link'];
}
it show out put is:
http://www.videoweed.es/file/b38300afda3e6
http://www.novamov.com/video/303a4428f6c6a
http://www.movshare.net/video/081aaa1356a6b
I need output only;
http://www.videoweed.es/file/b38300afda3e6

You have answer in your code. Just need to assemble it. check this:-
while($row2 = mysqli_fetch_array($result2)) {
if (strpos($row2['link'],'videoweed') !== false) {
echo $row2['link'];
}
}

Related

number_format() expects parameter 1 to be float [duplicate]

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 got this Error on my Page slider:
Warning: number_format() expects parameter 1 to be double, string given in /home/globalar/public_html/wp-content/themes/automotive_s1/includes/slider.php on line 30
<?php
if $str = floatval($str); ($post->post_type == "gtcd") {
the_title();
if (isset( $fields['price'])) {
echo ' | <span class="price_slider">'.' '.$symbols['currency'];
echo number_format($fields['price']).'</span> ';
} else {
echo '';
}
$fields['price']='8, 9858';
echo number_format((float)$fields['price']);
use (float) to parse correct way
You should check what value is inside $fields['price'].
Just do:
var_dump($fields['price']);
It's possible you have some spaces or , instead of .
fix it with define other variabel.
$tot=$row['total'];
$total=number_format($tot,2);
$tot2=$tot*1;
$vat=number_format($tot2*10/100,2);
maybe help

php break not working as intended? [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
I have a for loop that loops through xml. I then fetch results from the database and look for the id.
What happens is that when an id is found and the break happens, it stops both the while loop and the parent for loop. I just want to stop the while loop. How do I get this to work as intended?
$xml = simplexml_load_file('file/path/here');
$articles = $xml->article;
$total_articles = count($articles);
// Cycle through the list of articles
for($a=0; $a<$total_articles; $a++)
{
// Check if article already exists
// MySQLi select statement goes here
$exists = false;
while($a = $article_result->fetch_assoc())
{
if($a['article_id'] == $id)
{
$exists = true;
break 1;
}
}
}
you're setting $a to $article_result->fetch_assoc().
Here:
...
while($a = $article_result->fetch_assoc())
...
[] < 1 returns false for me, at least for php7.

Replace character depend on the data [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 5 years ago.
Improve this question
$defaultdata = "abcdef00000000000000000000000000";
$data1 = "271";
$output = "abcdef00000000000000000000000271";
How can I replace the string based on the data. For example, if the default data is abcdef00000000000000000000000000 , so it will replace when the data1 got value. So the output will be abcdef00000000000000000000000271. How can I do this?
I'd use substr:
$output = substr($defaultdata,0,strlen($defaultdata)-strlen($data1)) . $data1;
Applying it to your code
<?php
$defaultdata = "abcdef00000000000000000000000000";
$data1 = "271";
$output = substr($defaultdata,0,strlen($defaultdata)-strlen($data1)) . $data1;
echo $output;
?>
$output = substr($defaultdata, 0, strlen($defaultdata) - strlen($data1));
$output .= $data1
I think the easiest way to solve this is to use str_pad. It is a built in function made to tackle situations like yours. Then you can easly swap defaultdata to something other. The code is as follow:
$output = str_pad($data1, strlen($defaultdata), $defaultdata, STR_PAD_LEFT);

How to parse a specific json array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm a php beginner. I've got this kind of JSON ?
{
"rows":
[
["/page1.php","568"],
["/","78"],["/page2.php","4"],
["/page2.php","2"],
["/page3.php","1"],
["/search.php","1"]
]
}
to parse json i use
<?php
$json_file = file_get_contents('test.json');
$parsed_json = json_decode($json_file);
?>
But i don't know to parse each page and number. Anyone can help me on this surely basic issue ?
thanks a lot
$parsed_json will be an object, whose rows property is an array. The elements of this array are arrays, whose first element is the page name, the second element is the page number:
foreach ($parsed_json->rows as $page) {
$page_name = $page[0];
$page_number = $page[1];
echo "Page #" . $page_number . " on " . $page_name . "<br>";
}

How to split MySQL entry into different lines using PHP [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
Using simple HTML textarea I added some records in MySQL. While adding the entries I pressed enter to separate the lines. Now I want to select/display those records using PHP in bullets. I want each lines to be displayed into bullets.
E.g (the things I have added)
Name
Age
Gender
What I want
Name
Age
Gender
I am using following PHP script
$result = mysql_query("SELECT * FROM students");
echo "<ul>";
while($row = mysql_fetch_array($result))
{
echo '<li'.$row["details"].'</li>';
}
echo "</ul>";
While i'm not sure it's a good practice (what if the users forgot to use a newline/enter?) you can use the explode() function.
From the manual:
Returns an array of strings, each of which is a substring of string
formed by splitting it on boundaries formed by the string delimiter.
$listItems = explode("\n\n", $row['details']);
echo '<ul'>;
foreach($listItems as $item){
echo '<li>'. $item .'</li>';
}
echo '</ul>';
Please note: You're using mysql_ which is deprecated. Consider using PDO.
This should do the trick:
//assuming $result variable holds the db value from the textarea
$lines = explode("\n", $result);
echo "<ul>;
array_walk($lines, function($line) {
$sanitizedLine = htmlentities($line);
echo "<li>$sanitizedLine</li>";
});
echo "</ul>

Categories