|
I’m selecting data on an old database which has an abused status column. The status column has multiple pieces of information in it. Values are like ‘New Contact YYYY’, ‘Online YYYY’, ‘Updated YYYY’, ‘Withdrawn YYYY’, etc…. As you may have guessed, YYYY...
Started by John MacIntyre on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
If you simply want to extract a four digit year from the string, you could use PATINDEX
SELECT SUBSTRING(FieldName, PATINDEX('%[0-9][0-9][0-9][0-9]%', FieldName), 4) FROM TableName
If the year allways are the last 4:
SELECT right(FieldName,4) from table... .
|
|
Can anyone help me decode why this doesnt work?
$cssid = preg_replace("/'/", "", $cssid);
Trying to strip the single quote marks from some html...
Thanks! H
EDIT This is the full function - it's designed to rebuild the Drupal menu using images, and it...
Started by hfidgen on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
If str_replace("'","") doesn't work
And for the apostrophe replacement....
But why don’t you use str_replace as you’re replacing a fixed string?
$cssid = str_replace("'", "", $cssid);
escape the single quote.
Your code looks fine.
|
|
Hello again.
$string = preg_replace("#\[name=([a-zA-Z0-9 .-]+)*]#",'<td><a href="' . "$front_page/" . str_replace(' ', '-', "$1") . '">'."$1</a></td>",$string);
This part of script doesn't work:
str_replace(' ', '-', "$1")
I need...
Started by ciss on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
But you can do so by either using the e modifier in your regular expression :
$string = preg_replace("#\[name=([a-zA-Z0-9 .-]+)*]#e", '"<td><a href=\"$front_page....
The replacement is evaluated upfront and not on each replace.
|
Ask your Facebook Friends
|
Just migrating from PHP 5.2 to 5.3, lot of hard work! Is the following ok, or would you do something differently?
$cleanstring = ereg_replace("[^A-Za-z0-9]^[,]^[.]^[_]^[:]", "", $critvalue);
to
$cleanstring = preg_replace("[^A-Za-z0-9]^[,]^[.]^[_]^[:]...
Started by Abs on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Your regular expression; An example:
$out = preg_replace('![^0-9a-zA-Z]+!', '', $in);
Note I'm using criteria the following should do what you want:
$cleanstring = preg_replace('#[^a-zA-Z0-9.
|
|
I came to know PHP after Perl, so when I first found preg_* function I basically just used those. Later I read that str_replace() is faster when dealing with literal text. So my question is, can't preg_replace() be as efficient as str_replace() when the...
Started by kemp on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
It is possible the PHP team could jigger preg....
Joe
In theory yes, you're right.
Although trying to do the same in preg with str_replace, is actually slower if you're doing complicated stuff.
Use preg otherwise attempt with str_replace.
|
|
I want to do find and replace for example . In dreamweaver's find and replace
<p><strong>Business Development</strong></p>
into
<h4>Business Development</h4>
I have to change in lots of files.
I'm trying this
But it...
Started by Jitendra vyas on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at superuser):
This may help....
Simply change the Search field to Source Code and then it should be able to do it easily if you type your two statements in .
I saw the answer on your Stack Overflow question, however, I do this sort of thing all the time in Dreamweaver .
|
|
I have some text, something like this:
Paragraphs of text (SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT) Some additional paragraphs of text
What I want is to keep the Unknown Text , but get rid of the ( SOME KNOWN TEXT) and (SOME OTHER KNOWN TEXT...
Started by OneNerd on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
The first argument is the set of keys to replace, the second argument is what to replace....
If the two texts truly are known, you can do this:
$result = str_replace(array('(SOME KNOWN TEXT is better performance than a regular expression.
|
|
Okay, here's what I'm trying to do: I'm trying to use PHP to develop what's essentially a tiny subset of a markdown implementation, not worth using a full markdown class.
I need essentially do a str_replace, but alternate the replace string for every ...
Started by redwall_hp on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Personally, I'd loop through each occurrence of * or \ with a counter, and replace the character an asterisk, replace it with <em> , if it's odd then replace it with </em> , etc_replace('/\*([^*]+)\*/', '<em&....
|
|
Hello,
If have a following element in my XSL file:
<xsl:value-of select="replace(lower-case(@name), '_([a-z0-9])', '$1')" />
For example from 'get_polygene_lubricants' it makes 'getpolygenelubricants'.
What I want to do is to replace the first letter...
Started by Jagger on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The replace() function supposes that you have.
As required:
underLinedString
Below is the old solution.
|
|
I need to replace multiple instances of a certain string (question mark) with strings from an array. e.g. if the string I wish to replace appears 3 times and my array has a length of 3, the first one would be replaced by the first item in the array, the...
Started by Rob on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Preg_replace_callback can cater for a far wider range of circumstances..
Use preg_replace_callback() :
preg_replace always control the input string.
Information between callbacks but it's very flexible otherwise.
|