Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remove part of string in php

Posted on 2011-03-09
6
Medium Priority
?
454 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 …

705 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