tags:

views:

33

answers:

2

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'];
}
?>
A: 

You don't need to check stristr first, you can just do the str_replace right away:

$Title= str_replace(" (Part 1)","",$_POST['Title']);

UPDATE

You're original wasn't working because you messed up the parameter list for str_replace http://us.php.net/str_replace:

str_replace($search, $replace, $subject);
Mike Sherov
Haha, I feel like such an idiot. Thanks!
Nisto
A: 

There's one parameter missing there in str_replace()

http://php.net/manual/en/function.str-replace.php

Trefex