markduce Posted September 30, 2011 Share Posted September 30, 2011 Hello, I need to be able to find what is inbetween 2 values in a string of text. For example, <?php $string="Hello and welcome to the site. Click [link]welcome.php[/link] here to continue to the site"; ?> So I need some method of searching the string to see what values are in between the [link] and [/link] which I will then deal with in my own way. I have a feeling that I could do this with explode, but I'm not really sure. Any advice? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/248173-finding-what-is-in-between-2-values-similar-to-str_replace/ Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 You can use regular expressions: preg_match_all('/\[link\](.*)\[\/link\]/',$string,$matches); You will find the result in the $matches array. Link to comment https://forums.phpfreaks.com/topic/248173-finding-what-is-in-between-2-values-similar-to-str_replace/#findComment-1274356 Share on other sites More sharing options...
markduce Posted September 30, 2011 Author Share Posted September 30, 2011 Fantastic. Thank's Link to comment https://forums.phpfreaks.com/topic/248173-finding-what-is-in-between-2-values-similar-to-str_replace/#findComment-1274357 Share on other sites More sharing options...
markduce Posted September 30, 2011 Author Share Posted September 30, 2011 PS. Is there a way that I can mark this as solved or do moderators do that? Link to comment https://forums.phpfreaks.com/topic/248173-finding-what-is-in-between-2-values-similar-to-str_replace/#findComment-1274359 Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 You can mark it as solved but to be honest I have no idea where that is Link to comment https://forums.phpfreaks.com/topic/248173-finding-what-is-in-between-2-values-similar-to-str_replace/#findComment-1274363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.