I’m learning MySQL and using phpMyAdmin to make changes in my WordPress database for a store with thousands of products.
I’m trying to do a quick update where I pull out an URL and paste it into a shortcode I want to add.
Currently, each record in my table has this somewhere within a bunch of other text.
<input type="hidden" name="prtks" value="http://domainname/folder/filename.mp3"/>
I want to keep this and add to each record within the same field
[sc_embed_player_template1 fileurl="url from above"/"]
It’s rather tricky as I know I can find a substring by counting the characters, but is there a way to pull out the full URL from http all the way to the final .mp3?
thanks much!
This isn’t in MySQL, but if I understand your question correctly, you seem like you’re talking about doing this within a php file by doing something like the following:
This uses php
explode()
to break the string into an array based on ” characters.You can then just echo the 6th part (
$parts[5]
)Why not just use a simple regex to extract the url ?
If the file extensions are all 3 chars, you could use a regular expression like
http://*.{3}
to find the URL, but unless they have some sort of delimiter, it would be hard to find. you could tryhttp://*.(mp3|html|gif|png|exe|php|aif|wav)
and list all possible extensions if they’re different. You could also try only listing extensions that have more than 3 chars:http://*.({3}|html|jpeg|aiff|torrent)
.