|
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
|
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.
|
|
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.
|
|
I want to check if a variable has a valid year using a regular expression. Reading the bash manual I understand I could use the operator =~
Looking at the example below, I would expect to see "not OK" but I see "OK". What am I doing wrong?
i="test" if...
Started by idrosid on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
If [[ $i=~200[78] ]] ; then echo "OK" else echo "not OK" fi
Hi,
Could it be you need quotes around need spaces around the operator =~
i="test" if [[ $i =~ "200[78]" ]]; then echo "OK" else echo.
|
|
Usually I use David Sky's "bouncing ball" effect plug-ins, but I've always been
disappointed when "extra" space is created due to wrong delay times being
entered. For instance, several seconds of silence.
To counteract this, I created this plug-in, which...
Started by loopman on
, 2 posts
by 1 people.
Answer Snippets (Read the full thread at audacityteam):
VARZ01--Prep Zero ZT ECHO (v01.0).xls documentation (203.5 KiB.
Be helpful to beginner programmers.
|
|
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.
|
|
I need to get "yomomedia.com" if the HTTP_HOST is [ANY].yomomedia.com except in the cases where it is "dev.yomomedia.com" else it should return dev.yomomedia.com
echo preg_replace("/^([EVERYTHING-OTHER-THAN-DEV])\./Ui","",$_SERVER['SERVER_NAME'])
Just...
Started by farinspace on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
So....
So your expression means the same as the first three characters are not dev ( ^(?!dev) ) AND the first character is a full stop ( ^\ .
A negative passive group (lookahead) should do:
/^(?!dev).*\./Ui
Look-arounds do not “consume” any characters .
|
|
I want to store part of an id, and throw out the rest. For example, I have an html element with an id of 'element-12345'. I want to throw out 'element-' and keep '12345'. How can I accomplish this?
I can capture and echo the value, like this:
| storeAttribute...
Started by Andrew on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Element-(\d+)/i
That's a regular expression that would capture the numbers after the dash | elementID | | storeEval | '${elementID}'.replace("element-", "") | myID |
Now if I echo myID I get just the ID:
| echo | ${myID} | 12345 ....
|