Tonic-_- Posted June 26, 2009 Share Posted June 26, 2009 Hello, it's been awhile since i've gotten serious with php and i'm wondering how can I check for a specific string in the a number of lengths submitted by a form. Example: The user submits something like 12345678 I want to check the 3rd length 4th length and 5th length of the submitted text of each line. What I mean by each line is like a form with a textarea so they can submit each line of something.. Example: 12345678 yada yada blah blah nextline hereyada yada blah blah blahblah yadayada blah blah It's been quite some time since i've done php and can't seem to figure this out. I considered of use of detecting a certain string of text but I want to check only a certain length of it instead of a string variable. Now which if the string matches to the variables I have set how can I make it replace it with a new text or modifying the string.. Link to comment https://forums.phpfreaks.com/topic/163745-solved-checking-for-a-string-and-replacing/ Share on other sites More sharing options...
gevans Posted June 26, 2009 Share Posted June 26, 2009 With the following example you gave; 12345678 yada yada blah blah nextline hereyada yada blah blah blahblah yadayada blah blah what is your expected output? Link to comment https://forums.phpfreaks.com/topic/163745-solved-checking-for-a-string-and-replacing/#findComment-864010 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Author Share Posted June 26, 2009 Well what I want to do (more clearly) is have users submit hex codes (values) through a textarea form and check a length of the string for EACH LINE to see if it equals to another string I have stored in a selected variable. I sorta figured out the checking part but always had troubles checking each line submitted by a textarea box. Basically they submit stuff like 2040304 04040404 2040308 04040404 205030c 03030303 Check 204 and 205 for whatever my reason is and compare it to variables. I can do the actual check part just can't figure out how to read only the first 3 lengths of each line submitted by the text area. If the first line matches the variable string i have set then display a checkmark or something beside the first line.. And basically continue the way I stated above for each line or whatever. Link to comment https://forums.phpfreaks.com/topic/163745-solved-checking-for-a-string-and-replacing/#findComment-864017 Share on other sites More sharing options...
gevans Posted June 26, 2009 Share Posted June 26, 2009 <?php if(isset($_POST['your-textarea'])) { $code_array = explode("\n", $_POST['your-textarea']); foreach($code_array as $hex) { if(substr($hex, 0, 2) == "you-value") { //there's a match } } } Something like that should do the job for you. Link to comment https://forums.phpfreaks.com/topic/163745-solved-checking-for-a-string-and-replacing/#findComment-864020 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Author Share Posted June 26, 2009 Thanks, that does the job nicely. Link to comment https://forums.phpfreaks.com/topic/163745-solved-checking-for-a-string-and-replacing/#findComment-864022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.