0

Maybe the question title isn't very clear but I don't know how to describe.

I'll try to explain:

I have a MySQL query in my PHP code like this:

$statement = $pdo->prepare('SELECT name FROM persons WHERE name = :name');
$statement->execute(array(':name' => "Peter-Loew"));

What I want to to is to edit :name before comparing with "Peter-Loew".

I want to run a PHP code like this on :name before comparing with "Peter-Loew":

<?php
function url_replace($url_replace) {
$url_replace = str_ireplace(array('Ä','Ö','Ü'), array('Ae','Oe','Ue'), $url_replace);
$url_replace = preg_replace('~[^a-zA-Z0-9]+~', '-', $url_replace);
$url_replace = trim($url_replace, '-');
$url_replace = rtrim($url_replace, '-');
return $url_replace;
}
?>

How can I do this? Or, does anybody know how to call this what I'm looking for?

4
  • im down voting this because you have changed the question significantly since a valid answer was given Commented Feb 9, 2017 at 21:34
  • in addition to this here is a slug generator stackoverflow.com/questions/40641973/… Commented Feb 9, 2017 at 21:35
  • Having a lot of slugs which will show the same page may affect your seo. Commented Feb 9, 2017 at 21:36
  • @u_mulder What do you mean? Can you please clarify? Commented Feb 9, 2017 at 21:39

1 Answer 1

2

You're looking for mysql REPLACE:

$statement = $pdo->prepare('SELECT name FROM persons WHERE REPLACE(name, " ", "-") = :name');
$statement->execute(array(':name' => "Peter-Loew"));
Sign up to request clarification or add additional context in comments.

3 Comments

I don't understand why you ask for replacing - while your real problem is obviously of a different kind?
@David . . . Your question is quite clear and this answer answers it. If you have another question, then ask it as another question. Don't modify this one. That will just invalidate this correct answer, which might draw downvotes.
Sorry, my fault. I thought there's no way to do this in SQL itself and I wanted to keep the question clear. Sorry! I edited my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.