Solved

remove part of string in php

Posted on 2011-03-09
6
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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