Plug-in Posted August 27, 2011 Share Posted August 27, 2011 Does anybody know of a function or a way of letting me get the string between whatever characters? Say I had [sOMEWORD] text [sOMEWORD] then how could I go about getting the value "text", please note I'm not trying to make bbcode or similar. Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/ Share on other sites More sharing options...
codefossa Posted August 27, 2011 Share Posted August 27, 2011 $string = '[someword]some text[/someword]'; preg_replace('/\[someword\](.*?)\[\/someword\]/is', '$1', $string); Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/#findComment-1262576 Share on other sites More sharing options...
Plug-in Posted August 27, 2011 Author Share Posted August 27, 2011 Thank you very much, I'm not sure how to give reputation on this forum so if you can then possibly help me to the button Also if you have any good preg_replace(); tutorials that you've made or read that would be a great help so I can understand it Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/#findComment-1262577 Share on other sites More sharing options...
codefossa Posted August 27, 2011 Share Posted August 27, 2011 Thank you very much, I'm not sure how to give reputation on this forum so if you can then possibly help me to the button Also if you have any good preg_replace(); tutorials that you've made or read that would be a great help so I can understand it You can't give rep, just enjoy the results. The only thing you really need to learn with the preg_replace function is regex. There's a whole section here devoted to that. http://www.phpfreaks.com/forums/index.php?board=43.0 Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/#findComment-1262579 Share on other sites More sharing options...
Plug-in Posted August 27, 2011 Author Share Posted August 27, 2011 Thanks I'll take a look later. Just to save a thread how would I do line breaks in .txt file through fwrite? I tried \n but it just makes a space. Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/#findComment-1262587 Share on other sites More sharing options...
DavidAM Posted August 27, 2011 Share Posted August 27, 2011 1) There is a "SOLVED" button at the bottom of the page. Use it to mark the topic as solved. 2) You should start a new topic for a new question - especially since fwrite() has nothing to do with "String between characters" How are you looking at the results of your fwrite(). If you are viewing it in the browser, the browser changes a newline into a space. Use the View Source feature of the browser to see the newlines or look at the original file. If this is not the problem, we will probably have to see some code. Quote Link to comment https://forums.phpfreaks.com/topic/245812-string-between-characters/#findComment-1262606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.