ted_chou12 Posted February 3, 2007 Share Posted February 3, 2007 if there is a text like: hello[test]how are you[/test]test How can you get the value in between [test] and [/test]? notice that [test] and [/test] are different, therefore it is impossible to use explode... Ted Link to comment https://forums.phpfreaks.com/topic/36918-get-value-inbetween/ Share on other sites More sharing options...
utexas_pjm Posted February 3, 2007 Share Posted February 3, 2007 Use regex. This will get you started: \[test\].*\[\/test\] Link to comment https://forums.phpfreaks.com/topic/36918-get-value-inbetween/#findComment-176146 Share on other sites More sharing options...
ted_chou12 Posted February 3, 2007 Author Share Posted February 3, 2007 thanks, but can you please tell me how do i put this into regex? Thanks again ps, your display pic looks pretty cool, how does it work? Ted Link to comment https://forums.phpfreaks.com/topic/36918-get-value-inbetween/#findComment-176147 Share on other sites More sharing options...
utexas_pjm Posted February 3, 2007 Share Posted February 3, 2007 thanks, but can you please tell me how do i put this into regex? <?php $regex = '/\[test\].*\[\/test\]/'; $string = 'hello [test]how are you[/test] test'; preg_match($regex, $string, $matches); print_r($matches); // output: Array ( [0] => [test]how are you[/test] ) ?> ps, your display pic looks pretty cool, how does it work? I grabbed the geoip database from here: http://www.maxmind.com/app/geolitecity and wrote a small gd app that queries it: <?php require_once('dbIp.php'); $ip = $_SERVER['REMOTE_ADDR']; $ipArray = explode('.', $ip); $ipnum = 16777216*$ipArray[0] + 65536*$ipArray[1] + 256*$ipArray[2] + $ipArray[3]; $sql = 'SELECT * FROM ' . 'ip_addresses as addr ' . 'LEFT JOIN ip_locations ' . 'USING (locid) ' . 'WHERE start_ip <= "' . $ipnum . '" ' . 'AND end_ip >= "' . $ipnum . '"'; $rs = query($sql); $im = imagecreate(64, 64); $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 0); $dist = 12; imagestring($im, 1, 0, $dist*0, 'Are you from ', $textcolor); imagestring($im, 2, 0, $dist*1, $rs->fields['city'], $textcolor); imagestring($im, 2, 0, $dist*2, $rs->fields['region'] . ' ' . $rs->fields['country'], $textcolor); imagestring($im, 2, 0, $dist*3, $rs->fields['latitude'], $textcolor); imagestring($im, 2, 0, $dist*4, $rs->fields['longitude'] . '?', $textcolor); header("Content-type: image/png"); imagepng($im); ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/36918-get-value-inbetween/#findComment-176152 Share on other sites More sharing options...
ted_chou12 Posted February 3, 2007 Author Share Posted February 3, 2007 oh thanks, i see how regex works a bit now, and your geo thing is very cool. Ted Link to comment https://forums.phpfreaks.com/topic/36918-get-value-inbetween/#findComment-176157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.