Reply
Old 10-21-2009, 09:10 PM Check If Found?
Physicsguy's Avatar
Extreme Talker

Posts: 186
Name: Physicsguy
Location: On Earth
Trades: 0
Hello,

Would it be possible to make a script that checks if a certain character is found in a line? Like this:

String:

"Random text this is more random text and
the important character is right after this
next sentence right this is just some
random filler text |"

So the | is the important character.

How could I make a script that checks if the line contains the important character?

In more advanced terms, and probably another topic altogether;

How could I make something that checks for a character (a string) and echo everything up from that until the important character is found?

Like this:

$string = "before stuff 12345 This is the string this is the string | after stuff";
$check1 = strstr($string, '12345');
echo everything from the characters '12345'.
$check2 = strstr($string, '|');
stop echoing when the character '|' is found.

How would I do something like that?

I've been at it for days, feeling stupid, because I can't find it! I've come close, it does the first half of the script above;

PHP Code:
$reviewID $_GET["reviewID"]; //Set the variable 'reviewID' as from the URL.
$string file_get_contents("ffdatabase.txt");
$strings explode('|',$string);
$find strstr($string$reviewID);
echo 
$find
That finds the '$reviewID' in the database, then echoes everything up from that, stopping at the end of the file. I want it to stop echoing as soon as it hits a delimiter.

Thanks,

-PG

Last edited by Physicsguy; 10-21-2009 at 09:11 PM..
Physicsguy is online now
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
 
When You Register, These Ads Go Away!
Old 10-21-2009, 09:52 PM Re: Check If Found?
Physicsguy's Avatar
Extreme Talker

Posts: 186
Name: Physicsguy
Location: On Earth
Trades: 0
Never mind, I finally got it, with the help of my dad!

Here it is:

PHP Code:
$reviewID $_GET["reviewID"]; //Set the variable 'reviewID' as from the URL.

$transback = array(
"\n" => "<br />",
); 
//Simply changes all line breaks in the text file to <br/>s, feel free to add more, just don't delete that line.

$string file_get_contents("ffdatabase.txt");
$strings explode('|',$string);

$stringtotrans $strings[$reviewID];
$stringtrans strtr("$stringtotrans"$transback);

echo 
$stringtrans
Yeah! Woo!!! PAR-TAY!
Physicsguy is online now
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-21-2009, 11:00 PM Re: Check If Found?
wayfarer07's Avatar
NYE-KEE

Posts: 3,155
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
That's a good thing to learn. Exploding or splitting strings on a delimiter is an important thing to know how to do when programming.
__________________
Wayfarer | jQuery Tooltip Plugin | Mapbox: the jQuery Map
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-22-2009, 04:19 PM Re: Check If Found?
Physicsguy's Avatar
Extreme Talker

Posts: 186
Name: Physicsguy
Location: On Earth
Trades: 0
Thanks! This greatly helps and takes my program to the next step! Expect a few topics for that!
Physicsguy is online now
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-22-2009, 05:19 PM Re: Check If Found?
Brian07002's Avatar
Defies a Status

Posts: 1,593
Name: ...
Location: ...
Trades: 0
Programming is NOT fun...But the results can be AMAZING!
__________________
Sig Less - Have some site you want me to put here? Will put here for a couple of paypal bucks.
Brian07002 is online now
Reply With Quote
View Public Profile
 
Old 10-22-2009, 05:24 PM Re: Check If Found?
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,068
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Brian07002 View Post
Programming is NOT fun...
Speak for yourself. You should see how I spend my free time.
__________________
Tinsology | How to Post Code | EverythingDev
NullPointer is offline
Reply With Quote
View Public Profile
 
Old 10-22-2009, 05:26 PM Re: Check If Found?
Physicsguy's Avatar
Extreme Talker

Posts: 186
Name: Physicsguy
Location: On Earth
Trades: 0
Exactly!

I live programming, in a nerdy sort of way, but yes, the results CAN be fun!
Physicsguy is online now
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-22-2009, 08:03 PM Re: Check If Found?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,552
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
It's fun when you are learning and exploring with it, but it's NOT FUN when you are trying to meet a deadline!
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-25-2009, 07:46 AM Re: Check If Found?
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0
agree(100);
Quote:
Originally Posted by mgraphic View Post
It's fun when you are learning and exploring with it, but it's NOT FUN when you are trying to meet a deadline!
Code:
function agree(value)
{
    if (value> 99)
    {
       return 'agree 100%';
       break;
    } else {
       return 'I guess you're not a programmer then?';
       break;
   }
}
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-25-2009, 08:05 AM Re: Check If Found?
lizciz's Avatar
Ultra Talker

Posts: 330
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by chrishirst View Post
agree(100);


Code:
function agree(value)
{
    if (value> 99)
    {
       return 'agree 100%';
       break;
    } else {
       return 'I guess you're not a programmer then?';
       break;
   }
}
That code will get you an error, since you didn't escape the single quote in "you're", so agree(98).
__________________
596f75206d65616e20796f752063616e2061637475616c6c79 207265616420746869733f
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 10-25-2009, 09:11 AM Re: Check If Found?
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0

Good point!

I should have tested it
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-25-2009, 09:14 AM Re: Check If Found?
chrishirst's Avatar
Super Moderator

Posts: 22,257
Location: Blackpool. UK
Trades: 0
Or I should use correct grammar and put 'You are not' rather than be lazy by using a contraction
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-25-2009, 06:16 PM Re: Check If Found?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,552
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
Ha ha ha!
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Check If Found?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.21507 seconds with 13 queries