I’m looking for a way to write the following in only one preg_replace
$url = "stackoverflow";
if(!preg_match('/apple/',$url)){
$url = $url.".apple.com";
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ps: modifiers
ismight be useful.(?: )*makes non-capturing pattern. It matches zero or more instances of a(?!apple). Which is anything except ofappleand$0tells to take the whole string when pattern is matched. Example suggested above is not the same, because it will match anything when the string does not start withappleas?!applecondition is applied only once, at the beginning of the string.