rgb192
asked on
first part of parsing many lines
Ray's code works, but I want to know why
I want to discover what the first part does
I notice that the code breaks when I run
line
23
first-start:
text here<a href="/start.php?a=request -link& s=new-york &f=int ake&<b r>first-en d<br><br /> <b>Notice</b>: Undefined offset: 0 in <b>C:\Users\Acer\Documents \NuSphere PhpED\Projects\ray-website -parse2.ph p</b> on line <b>25</b><br /> <br>line<br>25<br>first-st art:<br><b r>first-en d<br>Array ( [0] => want-this-number [1] => want-this-number [2] => want-this-number [3] => want-this-number [4] => want-this-number ) <br>want-this-number<br>wa nt-this-nu mber<br>wa nt-this-nu mber<br>wa nt-this-nu mber<br>wa nt-this-nu mber
I want to discover what the first part does
I notice that the code breaks when I run
line
23
first-start:
text here<a href="/start.php?a=request
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28158846.html
$txt = <<<EOD
text here<a href="/start.php?a=request-link&s=new-york&f=intake&l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&s=new-york&f=intake&l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&s=new-york&f=intake&l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&s=new-york&f=intake&l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&s=new-york&f=intake&l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
EOD;
// START SIGNAL
$a = 'l=';
// STOP SIGNAL
$z = '"';
// MAKE AN ARRAY BY BREAKING STRING ON START SIGNAL
$arr = explode($a, $txt);
echo '<br>line<br>'.__LINE__.'<br>first-start:<br>'.$arr[0].'<br>first-end<br>';
unset($arr[0]);
echo '<br>line<br>'.__LINE__.'<br>first-start:<br>'.$arr[0].'<br>first-end<br>';
// USE THE STOP SIGNAL TO DECLOP THE ELEMENTS OF THE ARRAY
foreach ($arr as $sub)
{
$sub = explode($z, $sub);
$out[] = $sub[0];
}
// SHOW THE EXTRACTED SUBSTRINGS
print_r($out);
foreach ($out as $line){
echo '<br>'.$line;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ray putting
var_dump($arr);
twice
prevented the code from crashing after the
echo '<br>line<br>'.__LINE__.'< br>first-s tart:<br>' .$arr[0].' <br>first- end<br>';
I do not understand why
I can understand an if statement from Rsaylor
if (is_array($arr)) {
unset($arr[0]);
}
if(isset($arr[0])) {
echo '<br>line<br>'.__LINE__.'< br>first-s tart:<br>' .$arr[0].' <br>first- end<br>';
}
var_dump($arr);
twice
prevented the code from crashing after the
echo '<br>line<br>'.__LINE__.'<
I do not understand why
I can understand an if statement from Rsaylor
if (is_array($arr)) {
unset($arr[0]);
}
if(isset($arr[0])) {
echo '<br>line<br>'.__LINE__.'<
}
The error you were getting "crash" was it this?
Notice: Undefined offset: 0
If so, that error means you called an array "$arr[0]" after the array was unset or deleted. The error means the array did not exist when you called "$arr[0]"
Let me know if you need further help.
Notice: Undefined offset: 0
If so, that error means you called an array "$arr[0]" after the array was unset or deleted. The error means the array did not exist when you called "$arr[0]"
Let me know if you need further help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for explanation of output error
and telling me definition of array offset (key, value)
and telling me definition of array offset (key, value)
The key parts of the script are the explode() statements.
You can use var_dump() to print out the intermediate variables. You may want to use view-source in your browser, in case the intermediate variables contain any HTML.
Open in new window