Jump to content

extract string from string then display


calmchess

Recommended Posts

../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;

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?

 

$_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

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'];
}

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.