Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-21-2009, 09:10 PM Check If Found?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
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
__________________
Check out my
Please login or register to view this content. Registration is FREE

Last edited by Physicsguy; 10-21-2009 at 09:11 PM..
Physicsguy is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2009, 09:52 PM Re: Check If Found?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
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!
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 10-21-2009, 11:00 PM Re: Check If Found?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
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.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-22-2009, 04:19 PM Re: Check If Found?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
Thanks! This greatly helps and takes my program to the next step! Expect a few topics for that!
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 10-22-2009, 05:19 PM Re: Check If Found?
Brian07002's Avatar
Defies a Status

Posts: 2,138
Name: ...
Location: ...
Trades: 0
Programming is NOT fun...But the results can be AMAZING!
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 10-22-2009, 05:24 PM Re: Check If Found?
NullPointer's Avatar
Will Code for Food

Posts: 2,781
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-22-2009, 05:26 PM Re: Check If Found?
Physicsguy's Avatar
404 - Title not found

Latest Blog Post:
Challenges
Posts: 823
Name: Scott
Location: Ontario
Trades: 0
Exactly!

I live programming, in a nerdy sort of way, but yes, the results CAN be fun!
__________________
Check out my
Please login or register to view this content. Registration is FREE
Physicsguy is online now
Reply With Quote
View Public Profile
 
Old 10-22-2009, 08:03 PM Re: Check If Found?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
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
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-25-2009, 08:05 AM Re: Check If Found?
lizciz's Avatar
Webmaster Talker

Posts: 744
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).
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
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
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0

Good point!

I should have tested it
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-25-2009, 09:14 AM Re: Check If Found?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
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:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
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.43165 seconds with 12 queries