Solved

Remove part of string

Posted on 2013-01-14
11
299 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
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:yodercm
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:yodercm
ID: 38773981
Which part?  

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

?
0
 
LVL 27

Expert Comment

by:yodercm
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 27

Expert Comment

by:yodercm
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:yodercm
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:
yodercm 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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 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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now