find substring regx php
if (preg_match("/bwebb/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
find substring regx php
if (preg_match("/bwebb/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
regex php
ive never used regex expressions till now and had loads of difficulty trying to convert a [url]link here[/url] into an href for use with posting messages on a forum, heres what i manage to come up with:
$patterns = array(
"/[link](.*?)[/link]/",
"/[url](.*?)[/url]/",
"/[img](.*?)[/img]/",
"/[b](.*?)[/b]/",
"/[u](.*?)[/u]/",
"/[i](.*?)[/i]/"
);
$replacements = array(
"<a href="\1">\1</a>",
"<a href="\1">\1</a>",
"<img src="\1">",
"<b>\1</b>",
"<u>\1</u>",
"<i>\1</i>"
);
$newText = preg_replace($patterns,$replacements, $text);
at first it would collect ALL the tags into one link/bold/whatever, until i added the "?" i still dont fully understand it... but it works :)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us