Solved

Remove part of string

Posted on 2013-01-14
11
307 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 275 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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 …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 …

737 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