Get a specific line from object (php) - php

i get some URLS from HTML site by using
foreach($html->find('source') as $video)
if($video->type =='video/mp4') {
echo $video->src. '<br>';
my output looks like :
http://video.csfd.cz/321/321909/130228151/360.mp4
http://video.csfd.cz/321/321909/130228151/720.mp4
http://video.csfd.cz/321/321909/99476124/360.mp4
http://video.csfd.cz/321/321909/99476124/720.mp4
http://video.csfd.cz/321/321909/99476124/1080.mp4
and i have just no idea how to get just one of this links, i dont know much about objects so it looks pretty impossible for me to solve this problem.
What i try:
I was thinking about converting object to array and work with it, which sound pretty easy, problem is that if i use :
$pole = (array)$video;
echo "$pole[0]";
it says:
http://video.csfd.cz/321/321909/130228151/360.mp4
Notice: Undefined offset: 0 in C:\xampp\htdocs\xampp\ocul\subor.php on line 61
http://video.csfd.cz/321/321909/130228151/720.mp4
Notice: Undefined offset: 0 in C:\xampp\htdocs\xampp\ocul\subor.php on line 61
http://video.csfd.cz/321/321909/99476124/360.mp4
Notice: Undefined offset: 0 in C:\xampp\htdocs\xampp\ocul\subor.php on line 61
http://video.csfd.cz/321/321909/99476124/720.mp4
Notice: Undefined offset: 0 in C:\xampp\htdocs\xampp\ocul\subor.php on line 61
http://video.csfd.cz/321/321909/99476124/1080.mp4
Notice: Undefined offset: 0 in C:\xampp\htdocs\xampp\ocul\subor.php on line 61
if i use print_r the output is like tons of code , atleast for 1-2x A4 page, soemthing really crazy
So is there a way how to get one specific line from this (prefer to let me chose which one) , or some way to convert this output to array or anything like that?

It is a bad idea to convert objects into arrays. You could basicly store the links in an array while looping. Try this :
$links = array();
foreach ($html->find('source') as $video) {
if ($video->type == 'video/mp4') {
array_push($links, $video->src);
}
}
And then just use the $links array however you want :
echo $links[0];

Related

how to access array in array when inserting json data to database?

I have json file that contains of 50 lines of similar
"results":[{"score":0,"team_id":126266},{"score":0,"team_id":125798}].
I need to insert this to database, but I keep getting errors:
Notice: Undefined index: results[0]:score[0] in D:\xampp\htdocs\json\index.php on line 26
Notice: Undefined index: results[1]:score[0] in D:\xampp\htdocs\json\index.php on line 27
Notice: Undefined index: results[0]:team_id[0] in D:\xampp\htdocs\json\index.php on line 32
Notice: Undefined index: results[1]:team_id[0] in D:\xampp\htdocs\json\index.php on line 33
Here's the code:
$pirmo_oponento_rezultatas = $row['results[0]:score[0]'];
$antro_oponento_rezultatas = $row['results[1]:score[0]'];
$fk_Komandosid_Komandos = $row['results[0]:team_id[0]'];
$fk_Komandosid_Komandos1 = $row['results[1]:team_id[0]'];
$sql="INSERT INTO rungtynes (pirmo_oponento_rezultatas,antro_oponento_rezultatas,fk_Komandosid_Komandos,
fk_Komandosid_Komandos1) VALUES ('$pirmo_oponento_rezultatas','$antro_oponento_rezultatas',
'$fk_Komandosid_Komandos','$fk_Komandosid_Komandos1')";
You can access as below
$pirmo_oponento_rezultatas = $row['results'][0]['score'];
$antro_oponento_rezultatas = $row['results'][1]['score'];

What does it mean: Undefined variable: filter in ...?

Full error message:
Notice: Undefined variable: filter in
/srv/www/htdocs/test/tiltangle/dpd/query.php on line 104
line 104:
if (!($b1=="")) $filter=$filter." and b>=$b1";
line 35:
$b1=$_POST["b1"];
As you see it was defined.
I could imagine that your code looks like this:
if(...) {
$b1=$_POST["b1"];
}
...
if (!($b1=="")) $filter=$filter." and b>=$b1";
So it is possible that the first if-Condition is false, so $b1 is never set.

Notice: Undefined offset: 22 in C:\xampp\htdocs\authen.php on line 82

line numbber 82 is the if statement
$re_arr is an array containing 25 elements
if ($pass[0]==substr($re_arr[$i],0,1))
{
$pass1[0]=$re_arr[$i];
unset($re_arr[$i]);
$re_arr=array_values($re_arr);
}
what could be done to avoid the notice
Add a check if $re_arr[$i] exists.
if (!empty($re_arr[$i]) && $pass[0]==substr($re_arr[$i],0,1))
{
$pass1[0]=$re_arr[$i];
unset($re_arr[$i]);
$re_arr=array_values($re_arr);
}

Notice: Undefined index: category

Notice: Undefined index: category in /opt/lampp/htdocs/content/cron/check_deposits.php on line 18
$deposits=mysql_query("SELECT * FROM `deposits`");
while ($dp=mysql_fetch_array($deposits)) {
$received=0;
$txid='';
$txs=$wallet->listtransactions('',2000);
$txs=array_reverse($txs);
foreach ($txs as $tx) {
if($tx['category']!='receive') continue;
if ($tx['confirmations']<1) continue;
if ($tx['address']!=$dp['address']) continue;
$received=$tx['amount'];
$txid=$tx['txid'];
break;
This is how it came out of the box. I contacted support about the issue and they told me to make sure I was using PHP 5.3.1 which I am. What is wrong with this?
Here is a link to the full code:
http://diceking.tk/deposit.txt
You need to change from
if($tx['category']!='receive') continue;
to
if(isset($tx['category']) && $tx['category']!='receive') continue;
Check if the variables are set.
So, for the error about confirmations, you can use this:
if(isset($tx['confirmations']) && $tx['confirmations'] < 1) continue;
For the error about the undefined index: Category you can use this:
if(isset($tx['category']) && $tx['category']!='receive') continue;
I hope I'll helped you.
If this helped, please vote my answer.
Notice: Undefined index: amount in /opt/lampp/htdocs/content/cron/check_deposits.php on line 21
Notice: Undefined index: txid in /opt/lampp/htdocs/content/cron/check_deposits.php on line 22
Notice: Undefined index: amount in /opt/lampp/htdocs/content/cron/check_deposits.php on line 21
Notice: Undefined index: txid in /opt/lampp/htdocs/content/cron/check_deposits.php on line 22
Ahh so we have made it this far.. I tried this trick and it hated me for it:
if(isset($received=$tx['amount']) && $received=$tx['amount']) continue;

Undefined index - strange?

I experience something strange with an undefined index..
$vatcode = 'U25';
echo $this->vatcode_ids['U25']."\n";
echo $this->vatcode_ids[$vatcode]."\n";
foreach($this->vatcode_account_ids as $id => $vatcode){
echo $vatcode."\n";
echo $this->vatcode_ids[$vatcode]; // undefined index
}
this returns:
681
681
U25
Notice: Undefined index: U25 in /var/www/.....php on line 64
I don't get it?!
From empty line printed before Notice massage i assume your $vatcode variable contains some ending new line character. If so it does not match any key in $this->vatcode_ids array.
You should use some trimming function as Dan Lee suggested in comments.

Categories