anonīms Posted March 13, 2010 Report Share Posted March 13, 2010 Ceru, ka f-ju sauca tā. Apskatījos manuāli, bet īsti nedalaca. Piemēram ir kods no citas lapas source <h3 style='font-size:20px'>te iet teksts</h3> Kā es varētu iegūt to, kas ir iekšs tā h3.(Šajā gadījumā "te iet teksts")? Ideja ir izvlikt no viena foruma nikus pēc get ID. Quote Link to comment Share on other sites More sharing options...
briedis Posted March 13, 2010 Report Share Posted March 13, 2010 ar regulārajām izteiksmēm. Gūglē: ph get data between tags Quote Link to comment Share on other sites More sharing options...
anonīms Posted March 13, 2010 Author Report Share Posted March 13, 2010 čota nerabotaet. function getString($str, $start, $end) { $str_low = strtolower($str); $pos_start = strpos($str_low, $start); $pos_end = strpos($str_low, $end, ($pos_start + strlen($start))); if ( ($pos_start !== false) && ($pos_end !== false) ) { $pos1 = $pos_start + strlen($start); $pos2 = $pos_end - $pos1; return substr($str, $pos1, $pos2); } } $html_content = file_get_contents("http://php.lv/f"); //echo $html_content; $match = getString($html_contents, '<title>', '</title>'); echo $match; Warning: strpos() [function.strpos]: Offset not contained in string in Quote Link to comment Share on other sites More sharing options...
briedis Posted March 13, 2010 Report Share Posted March 13, 2010 ņem vērā, ka tā funkcija nestrādās, ja būs tagam atribūti :) Pameklē labāk kādu regulārās izteiksmes piegājienu šai problēmai... Quote Link to comment Share on other sites More sharing options...
2easy Posted March 13, 2010 Report Share Posted March 13, 2010 (edited) if (preg_match('/<h3.*?>(.*?)<\/h3>/', '<h3 style="font-size: 20px">te iet teksts</h3>', $m)) echo $m[1]; Edited March 13, 2010 by 2easy Quote Link to comment Share on other sites More sharing options...
marcis Posted March 13, 2010 Report Share Posted March 13, 2010 Konkrētais gadījums ir diezgan vienkāršs, bet būtībā šādās lietām derēs arī SimpleXML vai DOM. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.