?
Solved

Remove part of string

Posted on 2013-01-14
11
Medium Priority
?
311 Views
Last Modified: 2013-01-14
Hi,

I have a string, this string can contain "<a href='http://www.facebook.com/"
And if it does, will end with: "Facebook</span></a>".

I would like to remove that plus the stuff in between, but stuff in between the start and end can vary.

How do i remove this from the string?

Thanks!
0
Comment
Question by:peps03
[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
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38773966
Which part are you trying to keep?
0
 

Author Comment

by:peps03
ID: 38773972
nothing, well the rest of the string. minus this part.
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38773981
Which part?  

"<a href='http://www.facebook.com/

?
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.

 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38773986
$string="<a href='http://www.facebook.com/otherstuffFacebook</span></a>";

if (substr($string,0,32) == "<a href='http://www.facebook.com/" )
  $newstring=""<a href='http://www.facebook.com/";
else
0
 

Author Comment

by:peps03
ID: 38773990
string = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<a href='http://www.facebook.com/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFacebook</span></a>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

remove all from: <a href='http://www.facebook.com/
all in between, which can vary
to: Facebook</span></a>
keep: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38774002
so you want to keep what is between

<a href='http://www.facebook.com/

and

Facebook</span></a>

?
0
 

Author Comment

by:peps03
ID: 38774014
are you joking?

no dude. this:

<a href='http://www.facebook.com/

and all in between

Facebook</span></a>

is part of a larger string.

this:

<a href='http://www.facebook.com/

and all in between

Facebook</span></a>

needs to be removed out of the larger string...................
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38774029
You are not being clear.  Tell me exactly, from this, what do you want to have at the end?

$string = "aaaaaaa<a href='http://www.facebook.com/bbbbbbbFacebook</span></a>cccccccc"

And if you make one more insulting remark, you can wait for someone else to help you.  And I'm not "dude", I'm a woman with two PhDs.
0
 

Author Comment

by:peps03
ID: 38774038
$string = "aaaaaaa<a href='http://www.facebook.com/bbbbbbbFacebook</span></a>cccccccc"

bbbbbbbbb = random stuff

should become: aaaaaaacccccccc
0
 
LVL 27

Accepted Solution

by:
Cornelia Yoder earned 1100 total points
ID: 38774048
<?php

$string="aaaaaaa<a href='http://www.facebook.com/bbbbbbbFacebook</span></a>ccccccc";

$start1 = strpos($string, "<a href='http://www.facebook.com/");
$start2 = strpos($string, "Facebook</span></a>");

$parta = substr($string,0,$start1);
$partb = substr($string,$start2+19);

$newstring = $parta.$partb;

echo $newstring;

exit;
?>
0
 

Author Closing Comment

by:peps03
ID: 38774125
Thanks a lot!
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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

743 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