Solved

remove part of string in php

Posted on 2011-03-09
6
385 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

861 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