SQL PHP HTML ASP JavaScript articles and free scripts to download

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 plus2net.com. Use this site for your learning of web programming and design , php is one of the programming language";

$contents=my_strip("welcome","programming",$string);
echo $contents;
echo "<br>";
$contents=my_strip2("welcome","programming",$string);
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
Google+
RottNKorpse19-09-2009
Thanks a lot for this...exactly what I was looking for.
elden walden30-01-2010
great info-will use to change data in classified ad app.
prakash07-01-2013
very good information really it helped me.
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer