Regex str_replace

Would it be possible to incorporate a str_replace method with a regular expression, designed to catch url strings in a simple html < textfield > input type?

I'm considering something simple like a tip for the user to set it up as follows:

This is some text and click this link here.

Obviously the word "here" is a href to the url before it (or after it, if that makes a difference). The text input is drawn from a MySQL db.

I believe the start of my solution is something along the lines of:

$regex = '';
$pg = $row['pg'];
$pg = str_replace('{regex goes here}', $pg);

But I know things are missing. And then I would just output the $pg paragraph.

Answers


Check out preg_replace here, this is what you are lookin for.

// From the documentation.
preg_replace($regularExpression, $replacement, $subject); 

What you're looking for is preg_replace:

$pg = preg_replace('{regex goes here}', '{replacement goes here}', $pg);

Need Your Help

Apache 301 Redirect and preserving post data

apache rewrite http-post http-status-code-301

I have implemented SEO URLs using Apache 301 redirects to a 'redirect.cfm' in the root of the website which handles all URL building and content delivering.

Creating a random string with A-Z and 0-9 in Java

java random

As the title suggest I need to create a random, 17 characters long, ID. Something like "AJB53JHS232ERO0H1". The order of letters and numbers is also random. I thought of creating an array with lett...