Solved

remove part of string in php

Posted on 2011-03-09
6
367 Views
Last Modified: 2012-06-21
Hi all,

I have a string in a variable and I need to remove the question mark and everything before it.

Here is the string:

/website/docs/Ed/?ref=documents

I need to remove the Question mark itself and everything before it.

Hope you can help

Thanks

0
Comment
Question by:error77
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 35083895
<?php
$string = "/website/docs/Ed/?ref=documents";
echo substr(strrchr($string, "?"),1);
//returns ref=document
?>

Open in new window

0
 

Author Comment

by:error77
ID: 35084003
hmm it's returning:

bool(false)

Does it matter that the string is an array?    There's only 1 instance of the question mark :o/
0
 
LVL 13

Accepted Solution

by:
darren-w- earned 500 total points
ID: 35084053
yes, this only works on a string, so you will need to isolate it, ie:
<?php
$string = array("/website/docs/Ed/?ref=documents");
echo substr(strrchr($string[0], "?"),1);
//returns ref=document
?>

Open in new window



0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:error77
ID: 35084569
It's still returning:

bool(false)


This is what I'm doing:

$myNewArray = substr(strrchr($myArray[0], "?"),1);

Then:

var_dump(myNewArray);

I'm I doing this wrong?

Thanks

0
 

Author Comment

by:error77
ID: 35084692
OK, this is the contents of the array:

array(4) {
    ["onene"]=> string(38) "/website/docs/Ed/?ref=documents"
    ["counter"]=> string(1) "0"
    ["request"]=> string(424) "gfddfg-yE4.ggffJlWfffiJ9"
    ["ggfTwo"]=> string(199) "\"uid=1223321232&access=543%7C2._I543tBpygZGg__.340.1qadgebf3vlgU&expires=12965&sig=66555544\""
   
    }

Hope this helps

0
 

Author Closing Comment

by:error77
ID: 35085027
Got it working in the end. Thanks :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now