PHP String Extract

We can use php built in string function to create a function which can be used in various applications to collect part of a string. Here there will be one main string. We will supply one starting landmark or staring point and one ending landmark point or ending point. The string in between these two mark points we can extract and use in our application. We will be using two important functions stristr and substr to develop this function.

We can use this function in different applications. For example let us say we want to extract all names in one xml document.

<type>PHP programmer</type>
<name>Your name is here</name>

Here we can use <name> and </name> as two landmark points to extract the name from the above string.

There are two functions. One returns the part sting without landmark points and other one includes both landmark points. Here is the code.

function my_strip($start,$end,$total){

$total = stristr($total,$start);

$f2 = stristr($total,$end);

return substr($total,strlen($start),-strlen($f2));


function my_strip2($start,$end,$total){ // includes both landmarks

$total = stristr($total,$start);

$f2 = stristr($total,$end);

return substr($total,0,(strlen($total)-(strlen($f2) - strlen($end))));


$string="You are welcome to Use this site for your learning of web programming and design , php is one of the programming language";

echo $contents;
echo "<br>";
echo $contents;


The first function will display part of the string without the landmarks ( welcome and programming ) but second function will keep them at starting and at end.

Read how these functions are used to read the text within title tags of page


* indicates required
Subscribe to plus2net

    PHP String Functions


    Thanks a lot for this...exactly what I was looking for.
    elden walden


    great info-will use to change data in classified ad app.


    very good information really it helped me.

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer