2010-11-26 6 views
0

Ma chaîne recherche comme ci-dessous:problème découpant une chaîne en PHP

chercheurs de Harvard développent des piles à combustible à oxyde solide sans platine, ce qui pourrait être assez fiable et pas cher pour la technologie mobile.

<br clear="both" style="clear: both;"/> 
<br clear="both" style="clear: both;"/> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:4e19f3a5e1811fbd8d2609ab6e0b1790:xyHFPVLHAjBSu%2BHuriSZVqm9%2FODnAB81kZMY%2FW6XQhWC4ZbRzX%2BBHz7jOt1kjazUZT27efFh3vpwUMU%3D'><img border='0' title='Add to Twitter' alt='Add to Twitter' src='http://images.pheedo.com/images/mm/twitter.png'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:3e50e6b8d521eded6b35c7688aa906da:FrGGBNm1fSQsiuLmppzKM%2FATrKIoUDahb5X8uecXFxZVxeVzefUBbunDDSQIoM%2B7vZ%2FrMkI9MRbSJd0%3D'><img border='0' title='Add to Facebook' alt='Add to Facebook' src='http://images.pheedo.com/images/mm/facebook.gif'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:7e7e04c16c4c141c4117385690e52041:cBfF0Lt5lnF2klwL0yP1Z6C%2Bf6BV3FBNn1SMd9UUC1sTvBMcqqLi2LdjjD2Xx6LbCORRi%2F1sjoNWBYk%3D'><img border='0' title='Add to Slashdot' alt='Add to Slashdot' src='http://images.pheedo.com/images/mm/slashdot.png'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:abab99ee3bc19459ff3e8b7d8021840f:liR9O7Zfc0bI0Uuo10wyGIUoEOxlQXTWkWXuk6sb878dMYT2smVK1G5l0DxnIogEym5utExwYXrvUdM%3D'><img border='0' title='Add to digg' alt='Add to digg' src='http://images.pheedo.com/images/mm/digg_64x16.png'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:337479bf5b0ca164e90b9e6ee29a6bd2:Vo4lgAzFi7rA3OwEbIn3MCn8Wrc6ghW%2Bn8U%2FWvVnD%2FZAepXiRJLuKQ9jRNIB3tCaMfJBzkI0lN26WA%3D%3D'><img border='0' title='Add to del.icio.us' alt='Add to del.icio.us' src='http://images.pheedo.com/images/mm/delicious.gif'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:f1603669def1f797d29577bc6ffac6d8:L0FI9gIqTiSjo7LLh4IW%2FjEmU%2BevF%2Be%2B3Qh%2BEBIpZtBVoZeKf3mDbDWW%2FMjgIjP%2FujuheGGUDnffEyc%3D'><img border='0' title='Add to StumbleUpon' alt='Add to StumbleUpon' src='http://images.pheedo.com/images/mm/stumbleit.gif'/></a> 
<a style='font-size: 10px; color: maroon;' href='http://www.pheedcontent.com/hostedMorselClick.php?hfmm=v3:6935f5f46c828b54e7f0a20ec855a0bc:31pmU19Ai%2BBD4P%2Bra8NUD3ywNzoeb%2B%2B%2F3UGXkY0dOTgERp7CGY8D%2FkhkfhSbDSkXYVynDgrcwPHJ3Q%3D%3D'><img border='0' title='Email this Article' alt='Email this Article' src='http://images.pheedo.com/images/mm/emailthis.png'/></a> 
<br clear="both" style="clear: both;"/> 
<a href="http://ads.pheedo.com/click.phdo?s=08f79e2459078baab633a35da651dfa4&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=08f79e2459078baab633a35da651dfa4&p=1"/></a> 
<img alt="" height="0" width="0" border="0" style="display:none" src="http://segment-pixel.invitemedia.com/pixel?code=TechBiz 
&partnerID=167&key=segment"/><img alt="" height="0" width="0" border="0" style="display:none" src="http://pixel.quantserve.com/pixel/p-8bUhLiluj0fAw.gif?labels=pub.29821.rss.TechBiz 
.15217,cat.TechBiz 
.rss"/> 

de la chaîne ci-dessus je veux que la première ligne de celui-ci, à savoir: «Les chercheurs de Harvard développent des piles à combustible à oxyde solide sans platine, ce qui pourrait être assez fiable et pas cher pour la technologie mobile. "

Tout le reste n'est pas requis.

Pour ce faire, j'ai essayé:

$description = split(' \n', $string); 
$description = split('<', $string);  
$description = split('. ', $string); 

Mais aucun d'eux ne me donne le résultat nécessaire, qui ne serait que la première ligne, sans espaces et lignes ou après l'arrêt complet.

Peut-on m'aider avec ceci.

Aussi, si quelqu'un pouvait éditer mon texte, comme je suis incapable de coller mon exemple de chaîne, tel qu'il est réellement.

Cordialement Zeeshan

+0

Je ne vois aucun reste de la chaîne? –

+0

[Ne pas analyser HTML avec regexp] (http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) ou 'split()' . – grawity

Répondre

1

Dans regex le caractère point est un caractère spécial, vous devez échapper:

$description = split('\.', $string); 

En outre, split semble être dépréciée, vous devez utiliser preg_split: http://us.php.net/manual/en/function.preg-split.php

+0

Non, cela n'aide pas, car il divise le. pour les abréviations aussi. –

1

Quelque chose comme:

$description = current(explode("\n", $string)); 

devrait fonctionner correctement. Portez une attention particulière au double au lieu des guillemets simples.

Si vous faites plus de ce genre d'analyse, vous devriez envisager un analyseur HTML, tel qu'un simplehtmldom.

+0

J'ai essayé ce que vous avez dit, mais il sépare la chaîne en caractère. Je ne suis pas sûr, si après le fullstop, après la première ligne, il y a un retour ou des espaces. –

+0

@Zeeshan Rang: si vous ne savez pas, comment le savons-nous? –

Questions connexes