-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Did you learn anything from what I did?
-
Not much code to go on here. What exactly are you showing us and what is 'wrong' with it?
-
breadcrumb_add('Page', ucfirst($page['content_slug'])); The first argument I simply made a change to. The second arg I added the function to the var you were passing into the function. Pretty simple, huh? Of course I am assuming that your var is actually a string. Correct?
-
What exactly does 'crashing' mean to you/us? Are you getting an error message? Do you have error reporting enabled? You are calling a function with two arguments. What does the function do? It doesn't appear to return anything so why do you not use the ucfirst function on the 2 args before you use them in the function calll? That is what I would do. Or I would use the function on each of the args in the call. Show us this code that is 'crashing' your hole(?) website.
-
Ok - think I got it. This relies on always finding a period at the end of every sentence. $contents = "This is where cat is found. And it may be where cat is found a second time. And here it is the third occurrence of cat. Following the 3rd cat we have the 4th cat right here."; $sch_str = 'cat'; echo "Contents are:<br><br>"; echo "$contents<br><br>"; $last_start = 0; $last_end = 0; while ($pos = stripos($contents, $sch_str)) { // we have found the pos of the desired string // now locate the . prior to that pos $start = strrpos(substr($contents, 0, $pos), '.'); if (!$start) $start = 0; // now find the . following the current pos $end = stripos(substr($contents, $pos), '.') + $pos +1; // now output the sentence using start and end pos's echo "start $last_start, end " . ($last_end + $end) . " : " . substr($contents, $start, $end) . '<br>'; $contents = substr($contents, $end + 1); $last_start = $last_start + $end +1; $last_end = $last_end + $end +1; }
-
Aha! Let me work on that.
-
Do you want to find the chars before and after every occurrence of your search argument? Is that why the position comes up here? If so, then the code I gave you is not what you need. But I would really like to know what your task is.
-
So if you are searching for 'cat' you want to see the word 'cat' every time you hit it? What's the point of that? How about telling us/me what this exercise is supposed to accomplish? In real-world speak, not coding speak. And what do you mean by 'this position'? This is not a byte by byte search - it is a find a string search.
-
Here. $fname = 'BeerBottleBand.txt'; $sch_str = 'th'; echo "Looking for file $root$fname<br>"; if (is_file("$root$fname")) { echo "Found file $root$fname<br><br>"; $contents = file_get_contents("$root$fname"); echo "Contents are:<br><br>$contents<br><br>"; $cnt = substr_count(strtoupper($contents), strtoupper($sch_str)); echo "Found $cnt occurrences of '$sch_str' in all cases.<br>"; } else echo "File '$root$fname' not found"; If you want an exact match (ie, not all cases) then remove the strtoupper calls.
-
Have you looked into the manual's many 'string' functions yet? Time to do your own research if you want to become more than a mere hobbyist. Try this: https://www.php.net/manual/en/ref.strings.php Do you want to find exactly 'cat'? If so, you should look for " cat " to avoid getting 'scat' or 'catcher'. And why do you want all the occurrences of a simple word?
-
I personally see no reason at all to use JS on this task. Your data is on a server, not on a client. So use PHP to examine it and to build the response and view the results using php and html.
-
Some thoughts. Do you know the layout of your data file? Is it just a big 'paragraph' of text or is it laid out in lines that you can search one at a time for what you are looking for? I have given you the 'read line by line' approach but you might want to use the "file_get_contents()" function that was pointed out to you earlier. That will load the entire data file into a string variable on which you could then use a stripos() function call to locate the specific string that you are seeking and the the substr() function to extract that part to a separate variable. All of which can be found in the manual via the link I gave you previously. Sound like a plan?
-
I have showed you how to read the data and output it only. If you want to add some code to select the pieces of data that you want to find, that's for you to do yet. There are LOTS of string functions to use to examine the data to find what you are looking for. Take a look at the manual. Look up 'string' in the search button Here
-
So you are not a PHP coder? My example: $fname = 'BeerBottleBand.txt'; if (is_file($root.$fname)) { $hdl = fopen($root . $fname,'r'); while($line = fread($hdl,1000)) echo "$line<br>"; fclose($hdl); } else echo "File '$root$fname' not found"; Have fun!
-
You do realize that a session only last as long as the current lasts? That means when the user logs in (again?) he is beginning a new session so whatever was saved is no longer available. If you are looking to save a small piece of data or two, perhaps a cookie would be more useful, or a simple file that you first write out somewhere and then read back in when the user logs in again.
-
HELP! I need to make a simple PHP puzzle game for school....
ginerjm replied to lorenzo314737's topic in PHP Coding Help
Do you have a question perhaps, rather than a plea for help with your homework? And dont' expect a lot of people to click on your link. When you have a coding issue, try and isolate it and examine it carefully and only then post that block of code and tell us what is not doing correctly so that we can help you.- 1 reply
-
- 1
-
If you want to examine this file then you need to read it in and go thru it line/char by line/char. The function you are using (as it says in the manual) is not going to do that for you.
-
'title' => ucfirst($page['content_slug']) . ' ' . ucfirst($page['content_title']),
-
Inventory CONTROL is the headache. Not the app's problem since if control is managed then your app simply has to do and record the math. So - how is your organization going to manage that? Setting rules on how the people in the warehouse(?) gather items for shipping, how they open cases up when they don't have to, how they properly record what they actually do package for shipping. The two ends of this transaction: (a) your ordering system (that relies on proper inventory counts) and (b) the shipping/delivery system (that performs proper recording of its activity) must always agree or your app will appear to be at fault.
-
Thank you.
-
Are you giving up? Say it ain't so... The thread wasn't getting us anywhere and your use of terms was confusing. For one - pages don't have scripts.. Scripts produce pages. Let's just start a conversation about something you want to do. In non-nerd speak.
-
I don't want to go thru your html to find out the truth of this issue. Can you perhaps step back from programming and put on your real-world hat and tell us what you want to do? In real-world terms as your boss probably described to you. Is this an inventory review app? A sales-point app? What do you want the user to be able to do? And please, please don't use screen/page/script/etc. in your explanation. Just person-to-person, not coder-to-coder.
-
It seems from this discussion that the problem is not the coding of the app, but the handling of the inventory. You need to address that issur with those in control of that facet. Without that your app would appear to be a terrible expense despite the best effort you put into it. If those individuals cannot promise you a sound inventory number for your app to rely on, I'd back away rather than be blamed for the future entanglements you will appear to be responsible for.
-
What kind of code is this? I do not recognize your syntax. Is this from some framework perhaps?