I am trying to remove all text after the phrase "(paste this code" within a variable. I understand preg_replace can do this but how?
echo substr($str, 0, stripos($str, "(paste this code")); PHP: Should work, unless you wanted to include the paste this code bit
the content after the Paste string is always different, otherwise i would just use str_replace on that as well. unless im misunderstanding out preg_match works.
<?php /** * @author Interviolet * @package [$package] * @filename [$filename] * @copyright 2007 */ function clean_phrase( $phrase ) { if( preg_match( "~(\(paste this code)(.*)~", $phrase, $clean ) ) { return str_replace( $clean[2], "", $phrase ); } } function clean_phrase2( $phrase ) { if( preg_match( "~(\(paste this code)(.*)~", $phrase, $clean ) ) { return substr( $phrase, 0, strpos( $phrase, $clean[2] ) ); } } $phrase = "(paste this code some more text here"; echo clean_phrase( $phrase ); echo "<br />\n"; echo clean_phrase2( $phrase ); ?> PHP:
If thats really all you need : <?php $str = '(paste this code' . 'this will be stripped'; substr($str, 0, strlen('(paste this code')) ?> PHP:
thanks for the help guys, got it to work with this: echo(substr($content1, 0, strpos($content1, '(paste this code')));