PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'd like to build an extremely simple script that will be used in part of a larger script. This script will when correctly working echo if a string in the static HTML "<!--stuff-->" exists or not within the same file; thats it. I plan on erasing and reinserting this string from and back to the file. I'd like to keep this as simple as possible and since my files change a lot I need this to work with the static string we're looking if it's anywhere on the file (and not on say specifically line 7 or 23 or something predefined).
For simple reference, let's call our file "example.php". Both the script and the string we're looking for need to be part of "example.php".
example.php
<html><head><title></title></head>
<body>
<?php if () { echo 'found string';}
else () {echo'could not find string';}
<!--stuff-->
<p>stuff</p>
</body>
</html>
I'm sure this is going to deal with file command(s) and maybe some sort of _self syntax but this is why I'm asking.
if (!<!--stuff-->) {
echo 'This stuff that you are looking for,does not exist';
}
/*i think this is what you want. since i do not know how to search a php script via php,i cant tell how u can search a page.
This thing i wrote is,if whatever ur looking for does not exist,it will echo the does not exist*/
Not solved; I think you have JavaScript on your mind right now.
The method I need has to work in a larger script as an initial condition. I simply need the correct code to understand what syntax I need to use. Explaining the larger idea of the script this smaller script will fit in to will throw off this simple question of mine however.
Taking guesses isn't going to really help me as I need someone who knows PHP syntax to the extent that includes at least an idea of what syntax should probally be used (though there is so much syntax I've been browsing the PHP site for a good chunk of my day today). I'm sure it's some fsomething command but in a somewhat complicated setup.
Last edited by s.dot on Sat Mar 04, 2006 6:52 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
or use fopen() and loop through the file line by line until you find a match
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Thank you for trying a94060. If no one tried then we'd all just fall over and die.
scrotaye...
Well it's the right idea at least, but it's the classic problem of returning true when it's false. Remove "<!--stuff-->" and it will still say it found the string. I've seen this happen a few times in my other scripts but I'm simply not that skilled yet.
that does not work? that should seem to work because u are trying to match <--stuff--> with preg_match,and u already read th efile contents,so that should work unless you are getting some error or soemthing.
use if(preg_match("#<!--stuff-->#",$file)){ was found } else { was not found }
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.