thenext88 Posted March 13, 2007 Share Posted March 13, 2007 If I have a variable say... $a = 123456789; how do I take this, and echo "2345"; ? (without doing some kind of math) I want the the second, third, fourth, and fifth number to come out of that. Link to comment https://forums.phpfreaks.com/topic/42455-how-do-i/ Share on other sites More sharing options...
peeps Posted March 13, 2007 Share Posted March 13, 2007 Give this a try. substr($a,1,4); Link to comment https://forums.phpfreaks.com/topic/42455-how-do-i/#findComment-205987 Share on other sites More sharing options...
thenext88 Posted March 13, 2007 Author Share Posted March 13, 2007 Thank you very much I also have another question. If I have a sentences in a mysql database: the color is - blue "1" the color is - red "4" the color is - green "1" $sentence = $row['color']; Is there anyway I could make an output where it only displays the content between the - and the first " ? Reason I'm asking is because Substr wouldn't work in this case with varying amounts of letters. I know this is totally random but I'm trying to filter out content (and I can't use filter commands because I'm on php 4.4.2) Link to comment https://forums.phpfreaks.com/topic/42455-how-do-i/#findComment-205997 Share on other sites More sharing options...
sn33kyp3t3 Posted March 13, 2007 Share Posted March 13, 2007 The following code will print out the word "blue": $sentence = 'the color is - blue "1"'; preg_match( '/- (.*) \"/', $sentence, $results); echo $results[1]; search for regular expressions, or at the very least look at the documentation for preg_match. Link to comment https://forums.phpfreaks.com/topic/42455-how-do-i/#findComment-206015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.