Solved

Remove part of string

Posted on 2013-01-14
11
302 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

770 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