haku87 Posted April 22, 2007 Share Posted April 22, 2007 Hi. How am i going to extract the number in the < >. Eg. a. Testing <3> How to get the 3 out from this string? Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/ Share on other sites More sharing options...
Barand Posted April 22, 2007 Share Posted April 22, 2007 <?php $str = 'a. Testing <3>'; $x = strpos($str,'<') + 1; $y = strpos($str, '>', $x); echo substr ($str, $x, $y-$x); ?> Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235210 Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 another option <?php $string = "a. Testing <3>"; $patten = "<(.+)>"; ereg($patten, $string, $found); echo $found[1]; ?> Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235252 Share on other sites More sharing options...
Glyde Posted April 22, 2007 Share Posted April 22, 2007 <?php $string ="a. Testing <3>"; preg_match("@<(\d+)>@", $string, $match); print $match[1]; ?> Barand's method would be the fastest, however Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235253 Share on other sites More sharing options...
MadTechie Posted April 22, 2007 Share Posted April 22, 2007 True, @Glyde your script won't work unless you meant \s+ then again are we going by the title of the post or the contains LOL Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235289 Share on other sites More sharing options...
Glyde Posted April 22, 2007 Share Posted April 22, 2007 True, @Glyde your script won't work unless you meant \s+ then again are we going by the title of the post or the contains LOL Read what he said How am i going to extract the number in the < >. Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235345 Share on other sites More sharing options...
mjlogan Posted April 22, 2007 Share Posted April 22, 2007 http://php.invisibleshadow.com/2007/04/21/cutting-out-part-of-a-string/ echo cutBetween('a. Testing <3>','<','>'); Link to comment https://forums.phpfreaks.com/topic/48130-extracting-data-from-string/#findComment-235469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.