|
I often find this in scripts (and, I have to admit, write it myself):
a=`echo $x | sed "s/foo/bar/"`
or
if echo $x | grep foo then ... fi
Consider "foo" to include some regex stuff.
I feel that there should be - and most likely is - a better way to phrase...
Started by DevSolar on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at superuser):
Unless you assume a specific shell....
Sed 's/foo/bar/' <<< "foobie" grep 'this' <<< need it.
Fi
Where foo is a regular expression.
Fi
Consider using:
if [ $x =~ foo ] then ...
Be
Instead of:
if echo $x | grep foo then ...
|
|
I have a simple if-else statement--if true, I'd like it to echo this content:
<div id="login"> <h2>Login</h2> <div class="box"> <form method="POST" action="index.php/login"> Username/Email:<br /> <input type="text...
Started by Kevin Brown on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Another option would be to use output....
If(true) { ?> Regular HTML Here <?php } else { ?> Regular HTML Here <?php }
You can break out of PHP at any time using the '?> it.
You can simply break out of PHP in the if/else statement .
|
|
Hi,
We write a lot of code to htaccess but what is the best method to debug other than refreshing the page ?
Is there some way that I can write it out to a file ? or is there some echo/print function ?
Simply how do i know what my $1 $2 $3 is ?
Started by Devrim on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at serverfault):
Try these:
RewriteLog "/myfolder/mylogfile.log" RewriteLogLevel 3
These are just Regular.
|
Ask your Facebook Friends
|
Hi,
I wonder the general rule to use regular expression in if clause in bash?
Here is an example
$ gg=svm-grid-ch $ if [[ $gg == *grid* ]] ; then echo $gg; fi svm-grid-ch $ if [[ $gg == ^....grid* ]] ; then echo $gg; fi $ if [[ $gg == ....grid* ]] ; then...
Started by Tim on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Check http://tldp.org/LDP/abs represents a sequence of zero or more characters:
if [[ $gg == ????grid* ]] ; then echo $gg; fi
When using a regular expression, a dot represents....
If [[ $gg =~ ^....grid.* ]]
Use =~
for regular expression.
|
|
Is there a better way to output data to html page with PHP ?
if i like to make a div with some var in php i will write something like that
print ('<div>'.$var.'</div>);
or
echo "'<div>'.$var.'</div>'";
what is the PROPER way to...
Started by marc-andre menard on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Printf() is a direct analogy....
Most PHP code that I've seen uses echo .
The only difference between echo and print in PHP the choice between echo and print pretty much comes down to style.
echo $var;
Perhaps I'm missing something.
|
|
Hi all :)
I'm currently writing sort of a download manager and I was asking myself if that was possible:
if($ext == ('zip' || 'png')) { echo "Is it possible ?" }
It returns true everytime, so I guess it's not possible. But do you have an idea about how...
Started by Minishlink on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
If(preg_match("/^(zip|png)$/", $ext) { echo “It is possible!” }
Related question: Checking for file-extensions in PHP with Regular expressions
You could go' echo "It is possible"; break....
You can use regular expressions, e.g.
|
|
I'm writing a JavaScript application which should let the user to load & save files in his/her PC. To do so, I need a basic server used only to echo loaded and saved files between the client and the server, since JavaScript doesn't have direct access ...
Started by Stefano on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Files to a "dumb" secondary web-server, and retrieving them as regular files, it's probably better.
|
|
I have the following line:
<?php echo $this->__("mytext");?>somesometext")moretext
and I need a regular expression to grab 'mytext'. The best I could come up with is:
/\$this->__\([\'"](.*)[\'"]\)/
but in this case it returns:
mytext");?>...
Started by Manos Dilaverakis on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Better use PHP’s ability to parse its own code with token_get_all , step through the... .
/\$this->__\([\'"](.*?)[\'"]\)/
The ? makes the * quantifier ungreedy.
The ? switches the match-mode to ungreedy.
This->__\([\'"](.*?)[\'"]\)/
should work.
|
|
The PHP short tag <?= $var ?> has been deprecated for a while. Almost all PHP frameworks use the long form <?php echo $var ?> (e.g., symphony , Yii , Kohana ) Smarty is a famous PHP template engine which supports a shorter form {$var} Template...
Started by Wernight on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
In my foreach ($k as $v) { ?> <option value="<?php echo htmlentities($v['value']); ?>"><?php echo htmlentities($v['label']); ....
With it's own quirks to learn in order to accomplish the same thing with regular PHP.
|
|
Hi Guys ive tried to search for this answer all morning, but with no luck, all i want to do is match [slideshow or [gallery with the included [ bracket..
code as follows.
$gallery = get_post_meta($post->ID, 'gallery', true); if (preg_match("|^/[slideshow...
Started by Marty on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
("|^\[slideshow|", $gallery)
if (preg_match("/^\[slideshow/", $gallery)) { echo "Slideshow was forund"; } else if (preg_match("/^\[nggallery/", $gallery)) { echo "Gallery was found"; } else { echo "No Match.
|