calmchess Posted May 27, 2010 Share Posted May 27, 2010 how do i extract specific characters from a string and then use/display whats left over? Quote Link to comment Share on other sites More sharing options...
dyluck Posted May 27, 2010 Share Posted May 27, 2010 Can you write an example of the problem and then what you would like to see? Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 ../root/content/calmchess55.jpg...........extract..............use/display>>>>>> calmchess55.jpg PS. the lenght of the string is variable Quote Link to comment Share on other sites More sharing options...
dyluck Posted May 27, 2010 Share Posted May 27, 2010 ../root/content/calmchess55.jpg...........extract..............use/display>>>>>> calmchess55.jpg PS. the lenght of the string is variable $string = "../root/content/calmchess55.jpg"; $result = end(explode("/",$string)); echo $result; Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 i need to extract a string from it not explode it i would need to extact all the characters no just explode the slashes the slashes might not be there it was just an example Quote Link to comment Share on other sites More sharing options...
dyluck Posted May 27, 2010 Share Posted May 27, 2010 i need to extract a string from it not explode it i would need to extact all the characters no just explode the slashes the slashes might not be there it was just an example Oh ok. Unfortunatly your not being very descriptive. Do you know which pieces of string you will be extracting? Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 input username extract username use remaining string......sorry for not bein descriptive i just don't know how to do it so i'm writing this as we go. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted May 27, 2010 Share Posted May 27, 2010 Do you have the username saved as a session var? HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 $_POST['username'] this is part of an administrative web page so the username is being inputed.......i need to extact that username and then extract other string from that string if the username has a number on the end of it it will mess up my processing because i'm extracting the username along with its number if it has some then i change the new string by subtracting from its id number ........this probably isn't very clear but i think you will get the idea Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 here is what i'm trying <?php session_start();?> <form action="" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Admin Name:</td><td><input type="text" name="admin" maxlength="14" width= "30"value =""> </td></tr> <tr><td>Create in Private Room?:</td><td> <SELECT NAME="priv"> <OPTION VALUE="1">yes <OPTION VALUE="0">no </SELECT> </td></tr> <tr><td><a href="http://www.privatechatnow.com/currentwebsite/">Home</a></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="get" value="Get"></td></tr> </table> </form> <?php /* $myFile = "../recContent/trackrecsinfo.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $adminname; fwrite($fh, $stringData); fclose($fh); */ //del_movie("miamibitch69","../recContent/nonuser6","nonuser611.flv",0); if(isset($_POST['get'])){ include("../secure_php/admin_database.php"); $adminname = $_POST['admin']; $publishID = $_REQUEST['priv']; if($publishID == 0){ $result = mysql_query("SELECT picpath1 FROM page0.page0 where username='$adminname'") or die(mysql_error()); }else{ $result = mysql_query("SELECT picpath2 FROM page0.page0 where username='$adminname'") or die(mysql_error()); } $row = mysql_fetch_row($result); $db_arr0 = $row[0]; $arr_unser = unserialize($db_arr0); $_SESSION['arr_unser']=$arr_unser; $_SESSION['admin']=$adminname; //display table ?> <form action="" method="POST"> <SELECT NAME="string"> <?php foreach ($arr_unser as $value) { $plode0=explode(":",$value); //input values to change echo '<OPTION VALUE='.$plode0[0].':'.$plode0[1].':'.$plode0[2].'>'.$plode0[0].':'.$plode0[1].':'.$plode0[2]; } } ?> </SELECT> <tr><td colspan="2" align="right"><input type="submit" name="change" value="delete"></td></tr> </form> <?php if(isset($_POST['change'])){ //update all values by subtracting 1; foreach ($_SESSION['arr_unser'] as $value1) { if($_POST['string'] == $value1){ //get offset $pos = key($_SESSION['arr_unser']); array_splice($_SESSION['arr_unser'],$pos-1,1); } } $oneTime =0; foreach ($_SESSION['arr_unser'] as $value2) { $plode2=explode(":",$value2); $plode2[0]; $plode2[1]; //get inputed admin name subtract from string then process remaining data $len0=$plode2[1]; $plode2[2]; $len1=$plode2[2]; $sublen0 =strlen($plode2[0]); $plode3 = basename($plode2[1]); //$extract0 = substr($plode3[2],$len0,$sublen0); echo $plode3; $search0 = substr($plode2[1],$len0-5,1); $search1 = substr($plode2[1],$len0-6,1); ///////////////////////////////////// $search2 = substr($plode2[2],$len1-2,1); $search3 = substr($plode2[2],$len1-1,1); //////////////////////////////////////// //get last two characters if first is numerical then use it if not then only use if(is_numeric($search0)&& $search0 <=1){ $replace0 = substr_replace($plode2[1],"",$len0-5,1); } if($search1>0){ $replace1 = substr_replace($replace0,$search1-1,$len0-6,1); }else{ $replace2 = substr_replace($replace0,9,$len0-6,1); } //////////////////////////////////////////////////////////////////// ///////////// //////////// /////////// if(is_numeric($search2)&& $search2 <=1){ $replace3 = substr_replace($plode2[2],"",$len0-4,1); } if($search2>0){ $replace4 = substr_replace($replace3,$search2-1,$len0-4,1); $_SESSION['arr_unser']=$plode2[0].":".$replace1.":".$replace4.":"; echo $_SESSION['arr_unser']; }else{ $replace5 = substr_replace($replace3,9,$len0,1); $_SESSION['arr_unser']=$plode2[0].":".$replace2.":".$replace5.":"; echo $_SESSION['arr_unser']; } Quote Link to comment Share on other sites More sharing options...
teamatomic Posted May 27, 2010 Share Posted May 27, 2010 You explanation is still not really clear but...this is what I might do. work the username to see if it fits what I need then use str_replace to replace the username with nothing in the string I want to use. Make sense? HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
Kryptix Posted May 27, 2010 Share Posted May 27, 2010 I think the best way is for you to give us 10-20 EXAMPLE inputs and the data you want to extract from them. Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 need to extract calmchess55 from each link and then subtract 1 from each remaining string such as 1.jpg the username can be variable with or without a number so i need hack off the username and change the remaining string. ../recContent/calmchess55/calmchess551.jpg ../recContent/calmchess55/calmchess552.jpg ../recContent/calmchess55/calmchess553.jpg ../recContent/calmchess55/calmchess554.jpg Quote Link to comment Share on other sites More sharing options...
teamatomic Posted May 27, 2010 Share Posted May 27, 2010 Then the first thing to do is us basename on each string to get usernamexxx.jpg. Then use str_replace to change the username to nothing so you get xxx.jpg. Then explode on the dot so you get xxx and subtract 1 from it. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 yeah i think that will work thanks so much for your logic Quote Link to comment Share on other sites More sharing options...
calmchess Posted May 27, 2010 Author Share Posted May 27, 2010 that will definately work u saved me alot of time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.