Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Get Last Item In URL String


I realize how elementary this is, I apologize. Maybe that's why I can't find the right answer. I've tried everything from EXPLODEing the string to SUBSTR_REPLACE.

Can anyone tell me how to just get the last item in a URL string? Like turn this:

/mydirectory/myimg.jpg

into this:

myimg.jpg




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Replace An Item In The Url Search String
Using PHP 4, what is the most elegant way to replace a parameter
value in a url query string? I want to replace the "Order" parameter,
but it could occur anywhere in the query string.

myfile.php?Param1=Hi+there&Order=ColumnA&Param3=Bye+Bye
myfile.php?Order=ColumnA
myfile.php?Param1=Anotehr+example&Order=ColumnA

after applying this function, I'd like the result of the above examples
to be

myfile.php?Param1=Hi+there&Order=ColumnB&Param3=Bye+Bye
myfile.php?Order=ColumnB
myfile.php?Param1=Anotehr+example&Order=ColumnB

Array_unique - How-to Get First Item Value In Repeated Array Item
I would like to know how-to get the first value of repeated items too in an array using something like array_unique. Code:

Iterator First Item?
Let's say I have the code:

foreach($data as $row)
{
do something with each $row
}

Is there a way to do something specific to the first item iterated?
Pseudocode:

foreach($data as $row)
{
if first time through iteration do something with $row
else do something which each remaining $row
}

Is this possible? I think I could use a regular 'for' loop, using the
length of the $data array as a guide, and then an 'if..else' structure
to see if it is the first time through the 'for' loop, but I was
looking for a more elegant solution.

Get One Row, One Item From Database
I was trying to grab just one row and one field in that row from MySQL, but couldn't find a way other than: PHP Code:

Trying To Split The Item...
I'm trying to make a search thru my mySQL database, so it any keywords are found then I'm adding the details to the next item in an array that I create. I've tested the array and it is storing the information into the array properly because it echoes out all of the information correctly. My problem is that, at the beginning of each item in the array I have information that tells me what part of the database it was pulled from and the id number and also how many times the a keyword was found in that specific database entry. So you have something like this.. Code:

Deleting An Array Item
I have a standard array:
$foo = array(
0 => 'abc'
1 => 'def'
2 => 'ghi');

and I have a variable, $bar, which equals 'def' ... and I want to check
my array to see if the value of $bar exists in the array, and if it
does, delete it from the array.

if (in_array($bar, $foo)) {
// what goes here???
}

I've done this before, but for the life of me, I'm drawing a blank now.
Help a bruthah out?

Random Item Of An Array
What is the best way of picking out a random item of an array, regarding speed and CPU-usage ? I need a super fast way of picking out an ID from my MySQL db.

Search Item In Database
I made a function that does a case insensitive search. This works fine.
But i'd like to improve that script so that it also returns items from the database that are partly similar to the search string.

this is the script atm:

Delete Item From Database
I still can't figure out how to delete an item from my shoppingcart. I have tried different ways to do this, but its impossible.

-a button or link that deletes a item from my database
-the php script that deletes it

here is a suggestion:

$slett = "DELETE ID, VARE, MODELL, STR, ANTALL, PRIS,
TOTALPRIS FROM USER_TRACK
WHERE USER_ID = "$user_id"";

But how can i assign this to a button?

Updating Item Numbers (or IDs)
After a while of deleting records in a MySQL db, there gets to be the
gaps in the id numbering system. i.e. 1, 2, 3, 6, 7, 12, and so on.
Is there a way to renumber the id system in a table for 1, 2, 3, 4, 5,
6, etc without manually going in and changing those numbers?

Returning Autogenerated ID On New Item
Lets say you have a form that when saved to the mysql database creates
a unique incremental id. The form is just the first part of a series
of things the user can do, so once the ID is created, the page would
need to know immediately what this ID is. Is there a way to grab this
ID instantly once it is created? Obviously if this were a sign-up for
and a new user name and password are involved, you can have the user
login after the initial set up and this select statement would bring
back the ID. But the situation I have doesn't work like that.

The way I have been dealing with this is simply to have a select
statement after the initial insert that requests the record based on a
couple of other fields that are likely unique. But this seems like a
rather kludgy way of doing it. Is there some other solution.

What Does `Catalog`.item Like '%A-%' Mean? -MySQL?
I am looking at an old query and I cannot remember or figure out what this
part of the query means:

`Catalog`.item like '%A-%'
It is the like '%A-%'

I cannot figure out.

Then entire query is:[color=blue]
> SELECT *
> FROM `Catalog`
> WHERE `Catalog`.img_status = Ƈ' AND `Catalog`.item_type ='R' AND
> `Catalog`.item like '%A-%'
> ORDER BY `Catalog`.item_type[/color]

And will not work without the Like part

Pulling In One Item Of Four Categories
Ive got an offers table which contains name, category_id

I want to display all offers, however the first page will only display four offers (one of each category). My query is as follows so how do I do this part? Code:

Delete Item From Array
How do I search for an item within an array, then delete it?

Finding # Of Item From Query
I have a query that goes "SELECT item_name FROM products WHERE products.drink = 'juice'" . If I get back 12 results from this query I can make a list using a simple loop, that is fine . If I click on one of these list items I want to go to a detail page, again I can do this no probs.

How do I carry over to the detail page the number that the item appeared in the original list, for example if a result was "orange" and it was the 5th one in the list, how do I carry over the number 5 to the detail page?

Remove An Item From And Array Entirely
How do you remove an item from an array...

Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?

Populating Form Item From SQL Enum Set Rev#2
$sql = "SHOW COLUMNS FROM table LIKE 'subject' ";
$qry = mysql_query($sql) or die("Query not valid: " . mysql_error());
$res = mysql_fetch_object($qry);
// This returns a row with a field 'Type' containing 'enum(...)'

$res->Type = str_replace('enum('', '', $res->Type);
$res->Type = str_replace('')', '', $res->Type);
//now the string is something like this: one','two','three

$temp = explode('','',$res->Type);
//temp is an array with as much elements as the enum

while ($temp)
print array_pop($temp);


This way is much more easier using the elements since they are elements
of an array. Cleaver isn't it?

Shopping Cart Item Array
Trying to build a small simple shopping cart and I am having difficulty getting the solution. The cart is displaying each product, but it is overwriting the values. So if I have added 10 products, it shows ten items, but each item has the values of the last product I added.

I think that this may be due to me trying to use a key to store both an array and string at once, but Iam not sure. I have looked at other examples but due to different methods, syntax is throwing me off. Code:

Remove A Single Item From An Array
I have gathered an array of ID's. I need to go throught the array and find a specific ID and remove it from the array. Because we want to keep that ID. Any suggestion of how to do that.

Add Item To Shopping Cart Problem
i have a cart link in all of my listed products on the site. when i
press this link i will generate a url like this

http://www.mysite.com/index.htm?loc...art&productid=3

after i press this link the site cart.php will be included and add the
wanted product to the cart, and show the cart.

my problem now is after the cart is showed with the new product in it,
when i press the F5 key in the browser to refresh the site, the same
product will added to the cart once more, because the previous generated
url is unchanged in the browser.

have anyone a idea how to fix this problem?

How To Apply Css To A Table That Is The Only Item In A Php File Please
How to apply css to a table that is the only item in a php file please

In the page that has just the one table that is to
be included in the other 2 pages, there's some
heavy css going on, plus the text in the table
gets changed quite a lot on a daily basis.
Usually, in my program, I can highlught the text
that needs a different css applied to it and click
on the css style that applies to it, but because
the page only has the one table and nothing else,
there's no mention of the link to the styles page?

Preg_split First Item In Array Is Blank
could someone please explain to my why using the code below generates a blank item in $array[0] please. The 'x' from xbox360 is in $array[1]?

Language Depending Item Url's
I'm using a little newsflash item on my webpage, which is some text in an iframe. I have one newsflash item in English and one in another language, newsflash-english.html and newsflash-other.html How can I serve newsflash-english.html to english surfers and newsflash-other.html to not english users ? depending on the browser language ?

Redirecting To The ID Of Newest Item Created
I have a form that a user submits which creates a product. I want the user to be redirected to product.php?product_i=(the new product id)

The problem i'm having is that i dont know the ID of the new product created because the table is set to auto increment. How would i go about finding out the new ID and redirecting to that new product after it has just been created?

Selected Item To Use For Multiple Variables
I've got a list of 'items' and those 'items' have unique 'categories'.
I have 1 table for 'categories' that contains a list of category_ids and their 'category_names'. The other table is the 'item' list. And here's where I'm running into difficulty, I'd like to have the 'item' table contain the category_id from my 'categories' table as a Foreign Key and that category_id's 'category_name' in a 'category' field. I'm getting the Foreign Key, but I can't seem to grab the 'category_name' and assign it to my $category variable in the 'item' table.

I've got a page to insert items and a page to update these items. I was working with the update first. And I'm able to grab the list of categories and select the correct one, but I'm not seeing where to assign the category_name to the $category variable. Here's dropdown list: Code:

Explicit Numeric Keys Vs Item Position
Say if I have a mixed array:

$array = array("item1", "2"=>"item2", "5", "item4key"=>"item4")

Is it possible while looping through the array (foreach ($array as
$key=>$val)) to check if an item has an explicit key specified instead
of its automatically assigned position key?

Choose Random Item From List But With Different Weighting
I want to choose an item at random, but have different probabilities for each item. One easy way is just to create an array like

$a[]=1
$a[]=2
$a[]=3
$a[]=3

That way a random number between 1 and 4 would give the weighting I want, but it seems like there has to be a much smarter way to do this. I've seen some algorithms for random distributions, but they don't quite do what I want. Oh yeah - must not require a DB; this should work with values from a CSV or similar ...

Arrays : Returning A Reference To An Array Item ??
I am currently storing a set of objects inside an array,

$itemlist = array();
$itemlist[] = new item("myitem");
//...

and I am looking to develop a search function, which returns a
reference to the found item.

function &search_item($itemlist,"myitem") {
//...
}

I am trying to figure out how to obtain a reference to a given item in
an array.
Indeed, foreach() and each() seem to work on copies of the data in the
array.
For example:

$array = array("a","b","c","d");
print_r($array);
foreach($array as $v) $v="xxx";
print_r($array); // $array is unchanged

reset($array) ; while(list(,$v)=each($array)) $v="xxx";
print_r($array); // $array is unchanged, again

Creating A Form For An Item Tracking Website
I'm having trouble processing the html form, especially the "date found" portion. I also don't really know how to set up my tables in my database so that they work efficiently.  The information I an requesting with the form is: item_number, found_by, date_found, city, state, country.  I'm assuming that I will have to have more than one table in order for people to search by item_number or found_by etc.

I know these are kind of broad questions, but let me know if you'd like me to post what code I have, or stick the files on my FTP for download. I am using SQL Manager for a mysql client and Dreamweaver CS3 for design.

Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this:

$people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo');

...to this...

$people = array('Tom', 'Dick', 'Brenda', 'Jo');

The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove.

function removeItem ( $item ) {
   $len = count ( $_SESSION['basket_arr'] ) ;
   if ( $len == 1 ) {
      emptyBasket ( ) ;
   } else {
      for ( $i = 0 ; $i < $len ; $i++ ) {
         if ( $item->id == $_SESSION['basket_arr'][$i]->id ) {
            //$_SESSION['basket_arr'][$i] must go
         } } }}


Removing Item From Array Then Overwriting File
I have a bookings.txt file which has a list of dates each on a new line, for example: -

21/06/07
22/06/07
29/06/07
25/12/07
01/01/08

I also have a variable $event_dd_mm_yy which I want to remove from this file if found. Code:

How To Remove Unwanted Words/characters From Database Item
currently i dump some data into our database from another database. now, i found some wierd characters  at the end of each of those items. and there are like 500 items in my database table which has those.

is there a way that i can remove it using mysql query to be run in mysql or phpmyadmin
something like
update * from table where field name item has  and replace it with just blank?

hope you could help me with this.

Listing Table Data With An Option To Delete Each Individual Item.
Was wondering if anyone could help me with a PHP, MySQL problem. I am
completely new to PHP and MySQL. I have been trying to find a way to
list data from a table on a web page and after each individual item
have a hyperlink to allow users to delete the information listed. Can
anyone help?

i.e.
Name Age Sex
------------------------------------------
Adam 21 M delete
Betty 22 F delete
Chris 23 M delete
Daisy 24 F delete

------------------------------------------------------------------------------------------------------------------------------
(delete after 'Sex' would be the hyperlink to delete that entire line
(row) from the table).

Test If An Item Is An Object Or A Reference To An Object
Using php 4.4.4, let's say I have an array of objects or references to
objects. If I picked out an arbitrary element, $n, how would I know
if that was an object or a reference to an object?

Attaching A String To A Normal Word Without Loosing The String
In my database I have content rows that are either called <contentname>_title or <contentname>_fulltext. now when someone clicks a link on the site it goes to index.php?action=<contentname> so I guess you see where im going..

when someone goes to such a section index.php sees $action is used and attaches it to _title and _fulltext, so u get: $action_fulltext.. basicly of cuz php now sees it as one string '$action_fulltext' and not '$action'_fulltext.

String -> String That Is Compatible With Linux File System.
Does a function excist that converts a string to a string thats compatible
with linux file system?



Insert String Into String Based On Number Of Chars
Say I had

$string = "I swear I have seen this before.";

I want to add

$addme = "**";

into the original string after 10 characters.  How would I do this?

Help - Regexp For Extracting A String From A Larger String
I am developing a very basic CMS for a website I'm working on. One of the requirements is for the client to be able to post an image in their news posts, as well as links. I've got the links working (sort of, because I fear the way I have set it up may break images).

Ideally I would like something like BBcode but can't wrap my head around regular expressions.

Parse Part Of String (mid String Function ?)
Can someone tell me how to parse part of a string? I can use the following:

<?php
$text = $_SERVER['PHP_SELF']; //$PHP_SELF //(document.url);
echo $text;
?>

to get this result:

"Your currently at /test.php "

I just want to get "test.php " without the dash. I also need to parse out
parts of other strings. I know how to use Mid(), Left(), and Right() in VB,
but no clue for PHP.

Search A String And Return String Between Char?
I have a string like this;

Full Name (Department)

How can I split that string into seperate strings for Full Name and Department, so that everything before the () is the full name and everything between the () is the department?

Partially Replace A String With Data From The Same String...
I'm trying to write a script to help import some old HTML files as blog post for my website, these HTML files are 300-2000 lines long. I am currently using fgets() to read the files one line at a time, clean them and write them to the database in the appropriate format once the entire article is completed.

My issue is many of the links included on these post no longer exist (some date into the '90s) and I want as part of my importing function to "fix" these links as so. Code:

Searching For A Recurring String In A String
I am teaching myself PHP. I have an HTML page with various products
each with a specific reference in the form "Reference XXX". I would
like to put an email link below each product with the product reference
as part of the subject of the email link.

What kind of procedure would you use? Could you please put me in the...

String To Filename-friendly-string
I've got a database whith titles of pages and I want to use them in my filenames (with Modrewrite). But, I have to use a function to convert them to filename-friendly-strings.

e.g.
title:"What's thàt!?" should become something like:
whats-that(.html)

title:YOU & M€ should become you-m.html [ignoring strange characters]

Someone who has got that function?

Converting A Hex String To A Binary String?
I have a situation where I have an 8-byte string which is represented as 16 hex digits. How do I convert a 16 hex digit string to an 8-byte binary string?

I know I can use bin2hex to go from a binary string to a hex string (very useful)but is there a way to go the other direction? Right now I have a solution, which is to use a loop to go through the hex string one byte at a time, but that doesn't seem like a good way to do it. It seems like I should be able to use the pack() command, but I can't get it to work.

Extract A Part Of String From Other String
I would like to extract a piece of string inner oneother;
how rule for extraction all text inner this ">.......</a>
example if I have this string....

Replacing A String In A Larger String
i want to remove an email from a list of emails stored in a text file. using
str_replace i can replace an email with nothing, but if the list is serated by commans, that would result in this:

email@...,,email@...,email@...

with no email between 2 commas. if i replace the email address with a comma on
the end with nothing, it wouldn't work for the last one. if i replace the email address with a comma at the beginning, it wouldn't work for the first one. how can i avoid this or work around it?

Is There A Function To Search A String Within Another String ?
for e.g, fnding the word "hello" in this string : "hello world"...

Convert A String To A Numeric String ?
Is there a way to convert a string to a numeric string ?


Copyright © 2005-08 www.BigResource.com, All rights reserved