jzimmerlin Posted November 10, 2006 Share Posted November 10, 2006 Let's say I have a string that is... 01234567890abcd[ignorethis]blahblahblahIs there a method that can remove the stuff inside of the [ ]? Quote Link to comment Share on other sites More sharing options...
haaglin Posted November 10, 2006 Share Posted November 10, 2006 Take a look at php's ereg() function. complicated, but will do the job. look at http://www.regular-expressions.info/tutorial.html for some idea of what it can do. Quote Link to comment Share on other sites More sharing options...
Caesar Posted November 10, 2006 Share Posted November 10, 2006 For future reference, take a look at http://www.php.net first. A little effort before asking questions is always appreciated.Now...I basically did it for you here:[code]<?php $string = '01234567890abcd[ignorethis]blahblahblah'; preg_match('/[a-z0-9]+(\[[a-z0-9]+\])[a-z0-9]+/',$string,$matches); $cleantxt = str_replace($matches[1],'',$matches); $ignoredtxt = $matches[1]; echo"$cleantxt[0]"; // 01234567890abcdblahblahblah?> [/code] Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 10, 2006 Share Posted November 10, 2006 [code=php:0]<?php$string = '01234567890abcd[ignorethis]blahblahblah';echo preg_replace('/\[.*]/', '', $string);?>[/code] Quote Link to comment 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.