Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Removing Strings

extract string

  • Please log in to reply
5 replies to this topic

#1 Hunter100

Hunter100

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 292 posts
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly, Bash

Posted 12 May 2012 - 01:26 AM

Hello all,

I want to cut a string at the first occurrence of a period. Currently, I'm using substr_count to find out how many periods there are and using strstr to extract the characters prior to the first period; however, I want to take this string and remove it from the original string.

What functions should I be using to do so?

Thank you,
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 May 2012 - 02:46 AM

So you want the other half? Why not do as you do but with string length instead them?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 Hunter100

Hunter100

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 292 posts
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly, Bash

Posted 12 May 2012 - 03:15 AM

It may contain multiple periods though (like in a paragraph or a larger document). I simply want to remove the first sentence (space between the start of the string to the first period or the space in between periods).
  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 May 2012 - 03:44 AM

Use strpos to find the first occurance, add one and do strstr from that position to length of the whole?
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 Hunter100

Hunter100

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 292 posts
  • Programming Language:C, C++, PHP, Python, Delphi/Object Pascal, Assembly
  • Learning:Python, Assembly, Bash

Posted 12 May 2012 - 04:34 AM

So strpos() is the haystack and "." is the needle?
  • 0

#6 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 12 May 2012 - 05:10 AM

Something like this:
$s = substr($s, strpos($s, ".") + 1, length($s));

Have you ever thought of using the php documentation?
http://www.php.net/m...ref.strings.php
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download