I've got a section of code on a b2evo PHP site that does the following:
$content = preg_replace_callback(
'/[\x80-\xff]/',
create_function( '$j', 'return "&#".ord($j[0]).";";' ),
$content);
What does this section of code do? My guess is that it strips out ascii characters between 128 and 256, but I can't be sure.
Also, ...
i'm having a memory issue while testing a find/replace function.
Say the search subject is:
$subject = "I wrote an article in the A+ magazine.
It'\s very long and full of words.
I want to replace every A+ instance in this text by a link
to a page dedicated to A+.";
the string to be found :
$find='A+';
$find = preg_quote($find...
Yo, i'm trying to do this script working, but it doesn't work. How do i do it twice, the preg_replace_callback with two different functions. Thanks!
function prepend_proxy($matches) {
$url = (substr($_GET['url'], 0, 7) == 'http://') ? $_GET['url'] : "http://{$_GET['url']}";
$prepend = $matches[2] ? $matches[2] : $url;
$prepe...
I am trying to run preg_replace_callback, or an ob_start(), extract() combination
through a subdirectory. Something along the lines of these functions
<?php
/**
* Execute a PHP template file and return the result as a string.
*/
function apply_template($tpl_file, $vars = array(), $include_globals = true)
{
extract($vars);
if ($i...
I have borrowed code from this link http://stackoverflow.com/questions/959017/php-regex-templating-find-all-occurrences-of-var to implement a means of applying values to template fiies. This uses the preg_replace_callback() function
my preferred method of naming is name1.name2.name3=value, rather than name1_name2_name3=value, but the re...
Trying to create a simple text-translator in PHP.
It shoult match something like:
Bla bla {translator id="TEST" language="de"/}
The language can be optional
Blabla <translator id="TEST"/>
Here is the code:
$result = preg_replace_callback(
'#{translator(\s+(?\'attribute\'\w+)="(?\'value\'\w+)")+/}#i',
array($this, 'translateTe...
This is what I've got for for my RegEx, I was wondering if this is the best way.
I want to be able to find something similar regardless of the spacing between Identifiers and not be case sensitive. And if possible, not worry about order..
Example:
[Foreclosure ="Remax" URL="http://www.remax.com" Title = "4 Bedroom 2 Bath Condo"]
[F...
Regular expressions is just not my thing. :(
I have a string that may contain multiple sub strings such as:
[var1="111" var2="222" var3="222" var4="444"]
I basically need to replace each occurrence with the the results of a function that gets each variable.
$string = '[var1="111" var2="222" var3="333" var4="444"]';
$regex = 'var...
I'm using preg_replace_callback to substitute particular tokens within the string. But apart from actual token I need to know as well whether that token was first, second or third in a subject string. Is there any way to access that info?
I found an argument $count in preg_replace_callback definition (http://php.net/manual/en/function.p...
mmmh guys, i really hope my english is good enaught to explain what i need.
Lets take this example (that is just an example!) of code:
class Something(){
public function Lower($string){
return strtolower($string);
}
}
class Foo{
public $something;
public $reg;
public $string;
public function __construct(...
I have a Joomla plugin (not important in this context), which is designed to take an input with a load of numbers (within a paragraph of text) and replace them with a series of s.
My problem is that I need to do a preg_replace on my $article->text, but I don't know how to then apply the changes to the matched terms. I've seen the preg_r...
Consider the below HTML string
<p>This is a paragraph tag</p> <font>This is a font tag</font> <div>This is a div tag</div> <span>This is a span tag</span>
This string is processed to tokenize the text found in it and we get 2 results as below
1) Token Array :
$tokenArray == array(
'This is a paragraph tag',
'This is a div ta...
The site I'm working on has a database table filled with glossary terms. I am building a function that will take some HTML and replace the first instances of the glossary terms with tooltip links.
I am running into a problem though. Since it's not just one replace, the function is replacing text that has been inserted in previous itera...
I have a lot of option tags. I would like to remove the tags and get only the values.
This is the code:
<?php
$result = preg_replace('/<option value=\"\d+\" >([A-Za-z0-9]+)<\/option>/', '$1', $result);
?>
I cannot use strip_tags, strip_tags output:
id="pesq_marca" class="select164" size="1" onchange="exibeModelosSelectpesq_marca(thi...
In the function below, I want to match the keyword case insensitive (should match "Blue Yoga Mats" and "blue yoga mats")...
However, it currently only matches if the keyword is the same case.
$mykeyword = "Blue Yoga Mats";
$post->post_content = preg_replace_callback("/\b($mykeyword)\b/","doReplace", $post->post_content);
// the callb...