I have tried many combinations and a few different PHP functions, but I still can’t figure out why it doesn’t work.
Here’s the deal.. If someone uses the form and the (in this case) “Title” field ends with ” (Part 1)”, I want to delete that string, and if it doesn’t contain ” (Part 1)” I want to set a variable to the Title as it was submitted.
Here is my current script:
<?php
$partInStack = stristr($_POST['Title'], " (Part 1)");
if ($partInStack !== FALSE) {
$Title = str_replace($partInStack, "");
} else {
$Title = $_POST['Title'];
}
?>
You don’t need to check stristr first, you can just do the str_replace right away:
UPDATE
You’re original wasn’t working because you messed up the parameter list for str_replace http://us.php.net/str_replace: