Solved

Remove part of string

Posted on 2013-01-14
11
309 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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…

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