This question already has answers here:
MySQL string replace
(6 answers)
Closed 8 years ago.
I'd like to perform a find & replace in MySQL in GoDaddy's phpMyAdmin tool.
My table is called "wcswcd_posts", and I would like to find a URL, like:
http://wordpress.woodswcd.com/wordpress/wp-content/uploads/2013/11/drill.jpg
And replace it with:
/wordpress2/wp-content/uploads/2013/11/drill.jpg
Just not sure of what the syntax would be.
Thank you.
You are going to need to use the UPDATE statement & the REPLACE function
to change it try:
UPDATE wcswcd_posts SET url = REPLACE(url,'http://wordpress.woodswcd.com','')
REPLACE is a string function that replaces every occurrence of the 2nd string in the 1st string with the 3rd one.
By setting the 3rd argument in the REPLACE function to nothing, you will get rid of any occurence of http://wordpress.wordswcd.com leaving /wordpress/wp-content/uploads/2013/11/drill.jpg
This link should get you started.
Just replace http://wordpress.woodswcd.com/wordpress/ with http://wordpress.woodswcd.com/wordpress2/
Related
This question already has answers here:
How do I escape an exclamation mark in bash?
(4 answers)
Closed 2 years ago.
I want to pass a string to a php script which contains ! character. Like this
php cfg.php --name=smtppass --set="MYW!ORD"
But I get this error
bash: !ORD: event not found
On the other hand, if I pass "MYW\!ORD", I see this string is set when I query the file
smtppass MYW\!ORD
Any idea to fix that?
You could pass it like this:
php cfg.php --name=smtppass --set="MYW"'!'"ORD"
or a more lazy way would be to use single quotes.
php cfg.php --name=smtppass --set='MYW!ORD'
This happens because of Bash's history expansion, which is sometimes very dangerous, you could turn this feature off by typing set +H.
This question already has answers here:
SimpleXML Reading node with a hyphenated name
(2 answers)
Closed 3 years ago.
Hi guys! I need your help here..
I'm creating a simple XML-Reader in PHP/HTML atm and I've came across a problem.
One XML-Tag has a special character in it ("-") like:
<some-tag>foobar</some-tag>
How do I escape a character, while assigning a variable?
$value = $xml->some-tag
Doesn't work because PHP sees the character as an operator..
I've tried it with:
$value = $xml->'some-tag'
but that 'obviously' didn't work either.
Also this is my first post, so sorry in advance for any mistakes or broken rules.
In PHP you can use the content of a variable as a variable.
In your case you can do:
$myTagName = "some-tag";
$value = $xml->$myTagName;
EDIT
According to this post https://stackoverflow.com/a/3626928/4641073 you can use:
$value = $xml->{'some-tag'};
This question already has answers here:
PHP: Variables in a Postgresql Query
(2 answers)
Closed 3 years ago.
I’m working on a project where I need to use postgresql to update info. I need to take
Martin’s chik ‘n’ chips
And make change it to
Martin\’s chik \’n\’ chips
How would I do this? I’ve looked at other posts, and found out to use substr() to create the new string and strpos() to find the ‘s, and even setting a new variable to keep the position of the previous ‘
Edit: thanks everyone, clearly didn’t do enough research!
If in PHP:
Check out str_replace(). e.g.
$text = "Martin’s chik ‘n’ chips";
$apostrophe = array("'","`","‘","’");
$newtext = str_replace($apostrophe,"\'",$text);
In this specific example, if you don't have any of the 'fancy' apostrophes, check out addslashes() as this will solve everything for you
This question already has answers here:
Parse PHP code to extract function names?
(3 answers)
Closed 8 years ago.
i've few PHP files and i want to read but not execute these files to fetch function list from them, i can use include and then get_class_methods by calling a class but i don't want to do that, i simply just want to read php file and extract function list, i tried some RegEx patterns but it also matches in strings which i dont want.
I used following RegEx pattern but dont want to use it though it dont seems that the solution would be RegEx:
preg_match_all("%function ([^(\s]+)%", $source, $func);`
Two options:
get regex buddy and play around with your regex until it does what it needs to
implement the following algorithm:
search for the string "function"
get the characters to the right of function until you encounter " " (whitespace)
when you encounter the "{" after the function name and arguments, declare $c = 1
for each "{" you encounter, increment $c
for each "}" you encounter, decrement $c
when $c == 0, you have reached the end of the function
save the function in a variable
repeat
This question already has answers here:
parse youtube video id using preg_match [duplicate]
(10 answers)
Closed 9 years ago.
So I've got this RSS file that I'm trying to get part of a URL from. So here's what I tried (which is not working).
I've got this URL I can get easily enough:
http://www.youtube.com/watch?v=tUPjxGmh9i8&feature=youtube_gdata
I tried doing an $link = ltrim($link, 'http://www.youtube.com/watch?v='); in PHP and an $link = rtrim($trim, '&feature=youtube_gdata');
And it returned "UPjxGmh9i8". It cuts off the "t" in the front. The PHP.net documentation pages aren't the easiest for me to read and interpret, but I'm assuming that any individual character within the second parameter of ltrim() and rtrim() is taken out and this is not what I want. Is there some other solution I can use to grab only the text I want?
Any help is greatly appreciated.
This is how I would do it...
$query = parse_url(
'http://www.youtube.com/watch?v=tUPjxGmh9i8&feature=youtube_gdata',
PHP_URL_QUERY);
parse_str($query, $params);
$slug = get_magic_quotes_gpc() ? stripslashes($params['v']) : $params['v'];
CodePad.
The reason trim() (or its variants) won't work is because it accepts a character list (ordinal not significant), of which http://www.youtube.com/watch?v= contains t. It does not accept a string to remove.
Using PHP, cant you just grab the value of v?
$result = $_GET['v'];
var_dump($result);