Delete Before and after a string in PHP

I cannot find any info on deleting before and after a string.

example :

$string = 'Experts are ready to help solve your<a class ='problem' href='bla.php'>go there</a>. The quality of your question will directly ';

lets say i want the name of the href, how would i go about this?

Finished string


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
According to HTML 4.01, <a hrefs do not have names.  Named anchors are for locating place within the current page.

In PHP, you can locate items in a string with strpos() or one of the other string position funtions found on this page: .  There are notes there about the "=== operator" for checking the results.
ScottNL1Author Commented:
I am using the href as a example.

can you find me with a php script everything after
and before
and put that into a string.

or everything after '> and before </
the string should be "go there"

I just want find out how to do this.

I thank you in advance.

Dave BaldwinFixer of ProblemsCommented:
There are a lot of examples on the pages.  Usually you use strpos() to find the start of what you want and then substr() to extract it.  You actual method will depend on the data you're working with.

Your string example above will fail because you have 6 single quotes and no way for php to know what you mean.  Normally, you would either use double quotes on the ends or escape (\') the single quotes in the middle so php know where the correct start and end of the string is.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Try my below code...its resolve your problem...
$string = "Experts are ready to help solve your<a class ='problem' href='bla.php'>go there</a>. The quality of your question will directly";

print '<pre>';

echo $split_str[3];


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This code will show you all links and related link text in your given string
$str = 'Experts are ready to help solve your<a class ='problem' href='bla.php'>go there</a>. The quality of your question will directly ';

preg_match_all("/href=?[^<]+/i",$str,$lnk);// get link and text

foreach($lnk[0] as $linkdata)
	$link = substr($single_link[0],5);//remove href=
	$link = trim($link,"'\"");//remove double or single quote

	preg_match("/[>]+[a-z,A-Z, ,0-9]+/i",$linkdata,$link_text);
	$text = trim($link_text[0],">");
	print($text . " ==> " .$link . "<br>");

Open in new window

ScottNL1Author Commented:
That is what i was looking for, thanks allot.
both answers i can use.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.